分屏8部分

时间:2014-02-26 17:54:27

标签: android android-layout

我想将布局活动划分为8个ImageButton等效,当方向改变背景图像自动拉伸时,我该如何做一些像上传的图像

提前感谢

enter image description here trial 2 这是我失败的审判

<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>

3 个答案:

答案 0 :(得分:0)

对于所有图片按钮设置android:layout_width="0dp"

答案 1 :(得分:0)

设置android:layout_weight="0.125"

我建议转换所有宽度,如下所示:

android:layout_width="0dp"

并尝试将android:layout_weight添加到表格行中,以便他们可以将屏幕分成两半。 android:layout_weight="0.5"

编辑: 你怎么用LinearLayout尝试这一切?在LinearLayouts内创建两个LinearLayout(如行)(就像你的TableLayout一样)这样可以保证android:layout_weight能够正常工作吗?不要忘记设置LinearLayouts的android:orientation值,并根据该值设置宽度或高度0dp,并改为给出android:layout_weight值。

答案 2 :(得分:0)

主要变化:

  • 将宽度设置为0dp并且所有单元格的权重相等
  • 将height设置为match_parent,而不是wrap_content
  • 平均设置表格行的重量

使用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>
相关问题