我有一個佈局,其中一個元素動態地改變其大小(紅色imageView
)。問題是,下面的視圖或者不存在或者不對中。適應佈局以改變圖像的寬度查看
前兩個圖像顯示它看起來應該像:
與LinearLayout
低於設定到match_parent
: big imageView, match_parent http://i58.tinypic.com/35jedxt.png
與LinearLayout
低於設定到wrap_content
: small imageView, wrap_content http://i58.tinypic.com/255qjxs.png
這就是它的樣子在LinearLayout
layout:width
屬性是錯誤的: big imageView, wrap_content http://i61.tinypic.com/x1zk1h.png small imageView, match_parent http://i57.tinypic.com/2eutqmq.png
這裏是XML代碼:
<RelativeLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal"
android:background="#ffff0000" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<Space
android:layout_width="20px"
android:layout_height="20px"
android:layout_weight="1" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/imageView2"
android:background="#ff0000ff" />
<Space
android:layout_width="20px"
android:layout_height="20px"
android:layout_weight="1" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/imageView3"
android:background="#ff00ff00" />
<Space
android:layout_width="20px"
android:layout_height="20px"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
怎麼可能適應的佈局,所以綠色和藍色元素始終圍繞和空間當紅色imageView
很大時擴大,但當它太小時不切斷?
我更喜歡xml解決方案,因爲這只是一個簡單的例子,以編程方式執行此操作可能會變得複雜。
謝謝你,它與'android.support.v7.widget.GridLayout'工作! – agrajag