2013-05-21 17 views
7

शीर्षलेख (स्क्रीन के शीर्ष पर) और टैब (स्क्रीन के नीचे) के बीच स्क्रॉल दृश्य है। मैं जानना चाहता हूं कि क्या ImageView जो स्क्रॉलव्यू के अंदर है, पूरी तरह से दृश्यमान है या फोन स्क्रीन विंडो पर नहीं है।स्क्रॉल के अंदर देखें या नहीं,

enter image description here

+0

इसे आज़माएं: http://stackoverflow.com/a/25528434/3148266 – akshay7692

उत्तर

3

मैं निम्नलिखित तरीके से करना सुझाव है (दृष्टिकोण this question से मिलता-जुलता है)।

उदा। आप नीचे दिए गए एक्सएमएल है (मुझे यकीन है कि शीर्ष लेख और टैब ताकि वे याद कर रहे हैं क्या नहीं कर रहा हूँ):

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:id="@+id/scroller"> 
     <ImageView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center" 
      android:id="@+id/image" 
      android:src="@drawable/image001" 
      android:scaleType="fitXY" /> 
</ScrollView> 

फिर गतिविधि कैसा लग सकता है निम्नलिखित:

public class MyActivity extends Activity { 

    private static final String TAG = "MyActivity"; 

    private ScrollView mScroll = null; 
    private ImageView mImage = null; 

    private ViewTreeObserver.OnGlobalLayoutListener mLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      final Rect imageRect = new Rect(0, 0, mImage.getWidth(), mImage.getHeight()); 
      final Rect imageVisibleRect = new Rect(imageRect); 

      mScroll.getChildVisibleRect(mImage, imageVisibleRect, null); 

      if (imageVisibleRect.height() < imageRect.height() || 
        imageVisibleRect.width() < imageRect.width()) { 
       Log.w(TAG, "image is not fully visible"); 
      } else { 
       Log.w(TAG, "image is fully visible"); 
      } 

      mScroll.getViewTreeObserver().removeOnGlobalLayoutListener(mLayoutListener); 
     } 
    }; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Show the layout with the test view 
     setContentView(R.layout.main); 

     mScroll = (ScrollView) findViewById(R.id.scroller); 
     mImage = (ImageView) findViewById(R.id.image); 

     mScroll.getViewTreeObserver().addOnGlobalLayoutListener(mLayoutListener); 
    } 
} 

छोटे छवि के मामले में यह लॉग इन करेगा: छवि पूरी तरह से दिखाई दे रही है।

हालांकि, आप निम्न विसंगति के बारे में जागरूक (मेरी समझ के अनुसार) होना चाहिए: यदि आप बड़ी छवि है, लेकिन यह करने के लिए स्केलिंग (जैसे आप android:layout_width="wrap_content" सेट) जब यह छोटा देखो होगा कर रही है, लेकिन वास्तविक ImageView ऊंचाई हो जाएगा छवि की पूर्ण ऊंचाई (और ScrollView भी स्क्रॉलिंग होगी), इसलिए adjustViewBounds की आवश्यकता हो सकती है। उस व्यवहार का कारण यह है कि FrameLayoutdoesn't care about layout_width and layout_height of childs

संबंधित मुद्दे