2016-06-21 146 views
0

我有一个3个图像并排的布局。我用layout_weight对它们进行设置:Android如何调整其图像调整大小后的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:background="#888888" 
    tools:context="test_layout_resize.MainActivity"> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"/> 

    <RelativeLayout 
     android:id="@+id/layout1" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/image1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/hotdog"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"/> 

    <RelativeLayout 
     android:id="@+id/layout2" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/image2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/hotdog"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"/> 

    <RelativeLayout 
     android:id="@+id/layout3" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/image3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/hotdog"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 

出于某种原因,布局1,2和3的身高,原来热狗图像,而不是缩小之一:

3 hotdogs not at the top of the screen

我试过的getParent ()ImageView.onDraw()中的.requestLayout()或invalidate(),两者都没有改变任何东西。

如何将RelativeLayout的高度调整为新的ImageView高度?

回答

1

使用android:adjustViewBounds="true"在你的所有ImageView中都能解决你的问题。

希望它能帮助你:)

+0

非常感谢很多! – pkraau