2016-06-21 148 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