首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >平板电脑版面设计

平板电脑版面设计
EN

Stack Overflow用户
提问于 2014-05-02 04:24:25
回答 3查看 129关注 0票数 0

我在设计平板电脑的布局。我希望每个控件在彼此之间有相等的空间。如何正确地对齐所有这些?对不起,我不能附上这张照片,因为我没有10个名誉。请帮帮忙

这是布局代码,父布局是线性布局。

代码语言:javascript
复制
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="125dp"
    android:background="#517398"
    >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="125dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="30dp"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/image_agenda"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1.0"
            android:src="@drawable/agenda_view" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="125dp"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginRight="40dp"
            android:background="#000000" />

        <ImageButton
            android:id="@+id/image_month"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/month_view" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="40dp"
            android:background="#000000" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="125dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="30dp"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/image_day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1.0"
            android:src="@drawable/day_view" />
    </LinearLayout>
</RelativeLayout>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-05-02 04:37:39

代码语言:javascript
复制
// try this way,hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="125dp">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center">

            <ImageButton
                android:id="@+id/image_agenda"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" />
        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center">

            <ImageButton
                android:id="@+id/image_month"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" />
        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:gravity="center">

            <ImageButton
                android:id="@+id/image_day"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
票数 0
EN

Stack Overflow用户

发布于 2014-05-02 04:48:28

请检查下面的示例布局代码,我不知道您使用的是什么用途,也不知道如何使用中心元素2文本视图,所以现在我已经评论说,如果您希望中心元素(所有2个文本视图和图像按钮)具有相同的空间分布,那么您使用的公式layout_weight与我在此代码中使用的公式相同。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

代码语言:javascript
复制
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="125dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/image_agenda"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="125dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

  <!--   <TextView
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:layout_marginRight="40dp"
        android:background="#000000" /> -->

    <ImageButton
        android:id="@+id/image_month"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

   <!--  <TextView
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:background="#000000" /> -->
</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="125dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/image_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

如果你有任何疑问,你可以问我……

票数 0
EN

Stack Overflow用户

发布于 2014-05-02 05:11:25

尝试使用权重属性,避免使用相对布局。将WeightSum定义为父布局,将权重定义为子程序。它既适用于平板电脑,也适用于音像。

如果你想要划分空格,那就算了。若要宽度,则将宽度= 0dp提供给childs,如果Acc将其设置为高度,则在使用权重时将高度为0dp。

代码:

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="125dp"
    android:background="#517398"
    android:weightSum="9" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="125dp"
        android:layout_marginBottom="8dp"
        android:paddingLeft="30dp"
        android:layout_weight="3"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/image_agenda"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1.0"
            android:src="@drawable/agenda_view" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="125dp"
        android:layout_centerHorizontal="true"
        android:layout_weight="3"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginRight="40dp"
            android:background="#000000" />

        <ImageButton
            android:id="@+id/image_month"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:src="@drawable/month_view" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="40dp"
            android:background="#000000" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="125dp"
        android:layout_alignParentRight="true"
        android:layout_weight="3"
        android:orientation="horizontal"
        android:paddingRight="30dp" >

        <ImageButton
            android:id="@+id/image_day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1.0"
            android:src="@drawable/day_view" />
    </LinearLayout>

</LinearLayout>

注意:相对布局不支持权重或WeightSum。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23420723

复制
相关文章

相似问题

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