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

По какой-то причине, Layout1, 2 и 3 по высоте, что оригинального HotDog изображения, а не сморщенным один:

3 hotdogs not at the top of the screen

Я попытался GetParent() .requestLayout() или invalidate() в ImageView.onDraw(), ни одно из которых ничего не изменило.

Как изменить высоту по высоте RelativeLayout на новую высоту ImageView?

ответ

1

Используйте android:adjustViewBounds="true" внутри всего вашего ImageView, чтобы решить вашу проблему.

Надеюсь, это поможет вам :)

+0

Удивительное спасибо! – pkraau