我需要使用一组线性布局来构建一个布局.布局必须占用屏幕的定义百分比.我需要这样做,以便在所有设备上看起来类似.
问题:
右上方有一个textview(绿色框).每当我在文本视图中添加一些数据时,会干扰整个布局,如下图所示.但是当我们到达屏幕/布局的右端时,我需要自动打包数据.
请帮我解决这个问题.提前致谢
Image2 – 当我在textView中添加一些数据时,显示布局如何自动更改
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background" android:orientation="vertical" android:weightSum="100"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="91" android:weightSum="100"> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="40" android:weightSum="235"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:background="#ff0000" android:layout_weight="100"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ffff00" android:layout_weight="45"> <ViewFlipper android:id="@+id/view_flipper" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tvItemName" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> </ViewFlipper> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ffffff" android:layout_weight="90"> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="60" android:weightSum="100"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="30" android:background="#00ab00" android:weightSum="100"> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="fill_parent" android:textColor="#000000" android:text="Test data" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#cd00ab" android:layout_weight="70"> </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ab0000" android:layout_weight="9"> </LinearLayout> </LinearLayout>
解决方法
使用此XML文件.我已经为你做了修改.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background" android:orientation="vertical" android:weightSum="100" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="91" android:orientation="horizontal" android:weightSum="100" > <!-- Below is the first modification to layout_width --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="40" android:orientation="vertical" android:weightSum="235" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="100" android:background="#ff0000" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="45" android:background="#ffff00" android:orientation="vertical" > <ViewFlipper android:id="@+id/view_flipper" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tvItemName" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> </ViewFlipper> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="90" android:background="#ffffff" android:orientation="vertical" > </LinearLayout> </LinearLayout> <!-- Below is the second modification to layout_width --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="60" android:orientation="vertical" android:weightSum="100" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="30" android:background="#00ab00" android:orientation="vertical" android:weightSum="100" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="fill_parent" android:text="Test data Test dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest dataTest data" android:textColor="#000000" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="70" android:background="#cd00ab" android:orientation="vertical" > </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="9" android:background="#ab0000" > </LinearLayout> </LinearLayout>
对我来说看起来不错查看下面的快照.