安排在Android屏幕的各种界面元素的布局策略 [英] Layout strategies for arranging various interface elements on Android Screen

查看:186
本文介绍了安排在Android屏幕的各种界面元素的布局策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的Andr​​oid开发不具备的设计指南和正确的布局技术非常强的理解,但。我与需要类似如下的屏幕工作:

I am relatively new to android development and don't have a very strong understanding of design guidelines and right layout techniques, yet. I'm working with a screen that needs to look like the following:

在code我使用的是目前多个线性布局块的组合,我明白,这是不是打算对实现这样的布局的正确途径。

The code I am using currently is a mix of several linear layout blocks and I understand that this is not the right way of going about achieving such a layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.culami.WelcomePageActivity"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/welcome_msg"
        android:layout_gravity="center"
        android:textSize="50sp" />

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:layout_marginTop="15dp" >

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >

                <ImageView 
                    android:id="@+id/userIcon1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="3dp"
                    android:src="@drawable/user1"
                    android:contentDescription="@string/userProfileMSG"
                    android:layout_gravity="center"
                    android:onClick="" />

                <TextView 
                    android:id="@+id/nameUser1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/nameUser1"
                    android:layout_gravity="center"
                    android:textSize="24sp" />

        </LinearLayout>

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >

                <ImageView 
                    android:id="@+id/userIcon2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="3dp"
                    android:src="@drawable/user2"
                    android:contentDescription="@string/userProfileMSG"
                    android:layout_gravity="center"
                    android:onClick="" />

                <TextView 
                    android:id="@+id/nameUser2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/nameUser2"
                    android:layout_gravity="center"
                    android:textSize="24sp" />

        </LinearLayout>

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >

                <ImageView 
                    android:id="@+id/userIcon3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="3dp"
                    android:src="@drawable/user3"
                    android:contentDescription="@string/userProfileMSG"
                    android:layout_gravity="center"
                    android:onClick="" />

                <TextView 
                    android:id="@+id/nameUser3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/nameUser3"
                    android:layout_gravity="center"
                    android:textSize="24sp" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="horizontal" >

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >

                <ImageView 
                    android:id="@+id/userIcon4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="3dp"
                    android:src="@drawable/user4"
                    android:contentDescription="@string/userProfileMSG"
                    android:layout_gravity="center"
                    android:onClick="" />

                <TextView 
                    android:id="@+id/nameUser4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/nameUser4"
                    android:layout_gravity="center"
                    android:textSize="24sp" />

        </LinearLayout>

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >

                <ImageView 
                    android:id="@+id/addUserIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="3dp"
                    android:src="@drawable/adduser"
                    android:contentDescription="@string/userProfileMSG"
                    android:layout_gravity="center"
                    android:onClick="" />

                <TextView 
                    android:id="@+id/addUserText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/addUser"
                    android:layout_gravity="center"
                    android:textSize="24sp" />

        </LinearLayout>

        <LinearLayout 
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:orientation="vertical" >
        </LinearLayout>

    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="35dp"
        android:layout_marginBottom="10dp"
        android:text="@string/buttonSubmit"
        android:textSize="30sp"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:padding="5dp"
        android:background="@drawable/login_button_selector"
        android:layout_gravity="center" />

    <LinearLayout 
       android:layout_width="match_parent"
       android:layout_weight="0.3"
       android:layout_height="wrap_content"
       android:orientation="vertical" >
    </LinearLayout>

</LinearLayout>

有人能指导我为这样的布局处理,也是正确的方法,为我提供了一些设计指导我可能已经在这里侵犯。谢谢!

Can someone please guide me with the right approach for dealing with such layouts and also, provide me with some design guidelines I may have violated here. Thanks!

推荐答案

结果

    


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Welcome!"
    android:textSize="50dp"
    android:gravity="center_horizontal"
    android:id="@+id/welcome"/>

<LinearLayout
    android:layout_marginTop="30dp"
    android:layout_below="@+id/welcome"
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <ImageView
        android:src="@drawable/com_facebook_button_blue_normal"
        android:layout_width="match_parent"
        android:scaleType="fitXY"
        android:layout_height="100dp"
        android:layout_weight="0.33"
        android:id="@+id/im1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1234"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:src="@drawable/com_facebook_button_blue_normal"
            android:layout_width="match_parent"
            android:scaleType="fitXY"
            android:layout_height="100dp"
            android:layout_weight="0.33"
            android:id="@+id/im1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1234"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:src="@drawable/com_facebook_button_blue_normal"
            android:layout_width="match_parent"
            android:scaleType="fitXY"
            android:layout_height="100dp"
            android:layout_weight="0.33"
            android:id="@+id/im1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1234"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>

    </LinearLayout>

<LinearLayout
    android:layout_marginTop="15dp"
    android:layout_below="@+id/ll1"
    android:id="@+id/ll2"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:src="@drawable/com_facebook_button_blue_normal"
            android:layout_width="match_parent"
            android:scaleType="fitXY"
            android:layout_height="100dp"
            android:layout_weight="0.33"
            android:id="@+id/im1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1234"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:src="@drawable/com_facebook_button_blue_normal"
            android:layout_width="match_parent"
            android:scaleType="fitXY"
            android:layout_height="100dp"
            android:layout_weight="0.33"
            android:id="@+id/im1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1234"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:scaleType="fitXY"
            android:layout_height="100dp"
            android:layout_weight="0.33"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:textSize="20dp"/>

    </LinearLayout>

    </LinearLayout>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button"
    style="@android:style/Widget.Holo.Button.Borderless"
    android:text="Get Started"
    android:textSize="40dp"
    android:textColor="@color/black"
    android:padding="15dp"
    android:background="#4caf50"
    android:layout_alignParentBottom="true"/>


</RelativeLayout>

说明 - 相对布局(安排小部件flexicbility)父视图

Explanation - Relative layout as parent view (for flexicbility in arranging widgets).

TextView的id为欢迎的顶部的文本。 (U可以自定义U带重力和TEXTSIZE和所有的方式)。

TextView with id "welcome" for the top text. (u can customize it u way with gravity and textsize and all that).

的LinearLayout -

LinearLayout -

1)它具有水平方向。即,窗口小部件将horizantally布置。
2)它低于第一个文本视图:

1) it has horizontal orientation. That is, widgets will be arranged horizantally. 2) it is below first text view :

android:layout_below="@+id/welcome"

3)有3 imageviews(横放如上所述)。卢在它们的宽度,其0dps。因为我已经layout_weight来代替。每个重量为0.33,即它会occuoy的任何可用它水平33%。如果妳想要4张图片,ü可以使用重量0.25每个。

3) it has 3 imageviews (horizontally placed as stated above). Loo at their widths, its 0dps. Because I have used layout_weight instead. Weight for each is 0.33 i.e. it will occuoy 33% of whatever is available for it horizontally. If u want 4 images, u can use weight as 0.25 for each.

然后,我们有另一个线性布局,再有图像如上述之一。它被放置如下LL1。

Then we have another linear layout, again to have images as in the above one. it is placed below ll1.

最后,我们有一个按钮(U可以对准下方器112或父底部

Finally, we have a button (u can either align it below ll2 or at the parent bottom

这篇关于安排在Android屏幕的各种界面元素的布局策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆