我正在设计一个布局,但遇到了一个问题。不知怎么的,它在我的表格布局的右边有一个空白处,我无法填充它。如果谁有主意,请帮我一下好吗?
下面是我的布局xml和屏幕截图,以显示具体发生了什么;顺便说一句,我之所以使用tablelayout是为了使用与用户的交互将一些项目放在那里。
提前谢谢你
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="@+id/header" android:layout_height="wrap_content" android:layout_width="match_parent">
<TextView android:id="@+id/header_life_title" android:textSize="20sp" android:text="Life: " android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
<TextView android:id="@+id/header_life_value" android:textSize="20sp" android:text="20" android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
<Button android:text="Inc." android:id="@+id/header_btn_inc" android:layout_width="wrap_content" android:layout_height="35dp" android:layout_gravity="center_vertical">
<Button android:text="Dec." android:id="@+id/header_btn_dec" android:layout_width="wrap_content" android:layout_height="35dp"></Button>
<Button android:text="Put L." android:id="@+id/header_btn_putLand" android:layout_width="wrap_content" android:layout_height="35dp"></Button>
<Button android:text="Remove L." android:id="@+id/header_btn_removeLand" android:layout_width="wrap_content" android:layout_height="35sp">
<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/land_space">
</LinearLayout>
</LinearLayout>
<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/cardboard">
<LinearLayout android:layout_height="40dp" android:layout_width="match_parent" android:id="@+id/layout_menu">
<Spinner android:id="@+id/spinner_creature" android:layout_height="wrap_content" android:layout_width="150dp"></Spinner>
<Button android:id="@+id/btn_creature" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Cast"></Button>
<Spinner android:id="@+id/spinner_noncreature" android:layout_height="wrap_content" android:layout_width="wrap_content"></Spinner>
<Button android:id="@+id/btn_noncreature" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Cast"></Button>
<Button android:id="@+id/btn_delete" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Del."></Button>
</LinearLayout>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tableRow_cardImage"><![enter image description here][1]/TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tableRow_cardData"></TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tableRow_cardImage2"></TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tableRow_cardData2"></TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>http://imageshack.us/m/52/2443/111iyr.jpg发布于 2011-05-14 14:58:01
您可以使用LinearLayout的layout_weight属性来强制它内部的视图占用剩余空间。
将所有子视图的layout_weight属性设置为"1" in将使它们平均占用剩余空间:
<LinearLayout android:layout_height="40dp"
android:layout_width="match_parent" android:id="@+id/layout_menu">
<Spinner android:id="@+id/spinner_creature"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="150dp"></Spinner>
<Button android:id="@+id/btn_creature"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content" android:text="Cast"></Button>
<Spinner android:id="@+id/spinner_noncreature"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content"></Spinner>
<Button android:id="@+id/btn_noncreature"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content" android:text="Cast"></Button>
<Button android:id="@+id/btn_delete"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_width="wrap_content" android:text="Del."></Button>
</LinearLayout>子视图的宽度被设置为wrap_content,所以当你改变手机的方向时,它们不会变宽,即使父视图在水平方向上有更多的空间。
使用layout_weight,您可以设置每个子视图的部分,父视图的剩余空间应该填充多少。
有关更多参考,请访问:LinearLayout.LayoutParams
https://stackoverflow.com/questions/6000255
复制相似问题