假设我有一个的LinearLayout(宽度&高度match_parent)与weightSum = “5”,然后在水平方式为什么布局不符合指定的重量?
我把5 TableLayout(宽度&高度WRAP_CONTENT)与layout_weight =“1”,所以每个TableLayout都是其父项的1/5。
但是,之后,在每个TableLayout我把TextView的(宽度&高度WRAP_CONTENT)和每一件事情不顺心(从我的角度来看):
如果文本是长则强制其父级布局(在我们的示例中为TableLayout)到费用,因此即使指定了TextView的ellipsize =“end”,TableLayout从其LinearLayout父级的1/5比例也不再受到尊重。
好做一些可测量类后,我发现,设置layout_width比所有其他属性(如weightSum)更强。
在我来说,我设置TableLayout的宽度= WRAP_CONTENT也layout_weight =“1”,而是因为它是WRAP_CONTENT,它往往其内容后,花费和不尊重的重量。
任何人都可以给我一些解决方案,我的表格布局如何尊重重量?(因为我不希望我的布局不遵守儿童文本视图长度后的比例和支出)。
谢谢你的好意。这里是我的代码:
<!-- my code -->
< LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="5" >
<!-- table 1 -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:ellipsize="end"
android:maxLines="1"
android:text="test1test2test3test4test5"
android:textSize="20dp"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</TableLayout>
<!-- table 2 -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="test"
android:textSize="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</TableLayout>
<!-- table 3 -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="test"
android:textSize="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</TableLayout>
<!-- table 4 -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="test"
android:textSize="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</TableLayout>
<!-- table 5 -->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="test"
android:textSize="20dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</TableLayout>
</LinearLayout>
非常感谢您的答案!它的工作原理。我不知道0DP,然后设置重量,但它很好:)。关于TableLayout内部,我的未来工作中将充满其他视图。 –