2013-05-21 14 views

答えて

3

私は、次のよう(なアプローチがthis questionのものと類似している)を行うことをお勧めします。

など。あなたは(私は彼らが見逃しているように、ヘッダーとタブが何であるかわからないんだけど)次のXMLを持っている:

<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です。

関連する問題