我想将布局活动划分为相当于8个ImageButton,当方向改变背景图像自动拉伸时,我如何做一些事情,如上传的图像
提前感谢


这是我失败的试验
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onFerakClick"
android:src="@drawable/ic_ferak" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onHolyBookClick"
android:src="@drawable/ic_holybook" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onMzahebClick"
android:src="@drawable/ic_mzaheb" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onShbhatListClick"
android:src="@drawable/ic_shbhat" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onFactsImagePagerClick"
android:src="@drawable/ic_facts" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onMapsGridClick"
android:src="@drawable/ic_maps" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onSearchClick"
android:src="@drawable/ic_search" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onProductsGalleryClick"
android:src="@drawable/ic_product" />
</TableRow>
</TableLayout>发布于 2014-02-27 02:07:31
对于所有的图像按钮,请设置android:layout_width="0dp"
发布于 2014-02-27 02:10:49
设置android:layout_weight="0.125"
我建议转换所有宽度,如下所示:
android:layout_width="0dp"并尝试将android:layout_weight添加到表行,以便它们可以将屏幕一分为二。android:layout_weight="0.5"
编辑:你可以用LinearLayout来尝试一下吗?在LinearLayout(比如你的TableLayout)中创建两个LinearLayouts (比如行),这样就可以保证android:layout_weight正常工作了吗?别忘了设置LinearLayouts的android:orientation值,并根据该值设置宽度或高度0dp,然后给出android:layout_weight值。
发布于 2014-02-27 02:43:18
主要变化:
工作xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onFerakClick"
android:src="@drawable/ic_ferak" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onHolyBookClick"
android:src="@drawable/ic_action_holybook" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onMzahebClick"
android:src="@drawable/ic_mzaheb" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onShbhatListClick"
android:src="@drawable/ic_shbat" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onFactsImagePagerClick"
android:src="@drawable/ic_facts" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onMapsGridClick"
android:src="@drawable/ic_map" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onSearchClick"
android:src="@drawable/ic_search" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:onClick="onProductsGalleryClick"
android:src="@drawable/ic_product" />
</TableRow>
</TableLayout>https://stackoverflow.com/questions/22049372
复制相似问题