首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拆分屏幕8部分

拆分屏幕8部分
EN

Stack Overflow用户
提问于 2014-02-27 01:54:27
回答 3查看 399关注 0票数 0

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

提前感谢

这是我失败的试验

代码语言:javascript
复制
<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>
EN

回答 3

Stack Overflow用户

发布于 2014-02-27 02:07:31

对于所有的图像按钮,请设置android:layout_width="0dp"

票数 0
EN

Stack Overflow用户

发布于 2014-02-27 02:10:49

设置android:layout_weight="0.125"

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

代码语言:javascript
复制
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值。

票数 0
EN

Stack Overflow用户

发布于 2014-02-27 02:43:18

主要变化:

  • 将所有单元格的宽度和权重设置为0dp,
  • 将高度设置为match_parent,而不是将表格行的权重设置为

工作xml:

代码语言:javascript
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22049372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档