Android版的LinearLayout换行符XML [英] Android LinearLayout Line Breaks in XML

查看:171
本文介绍了Android版的LinearLayout换行符XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计获得客户信息的活动。第一行得到的名字,2号线街道地址,第三行是城市,州和邮编。我能实现我想用什么的RelativeLayout,并采用了android:layout_below和android:layout_toRightOf,但后来我不得不专门指示我的观点的宽度。当用户重新定位或新旧版本的Andr​​oid,一切都是大小不同的交换机之间这种宽度看起来很奇怪。我想利用的LinearLayout的权重功能,但一切都只是出现都在一行。我要如何插入断行到的LinearLayout中创建视图的列吗?

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的TextView
机器人:ID =@ + ID / custLabel
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =25
机器人:layout_width =0dip
机器人:文字=名称/>
<的EditText
机器人:ID =@ + ID /客户
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =75
机器人:layout_width =0dip/>
<的TextView
机器人:ID =@ + ID / addressLabel
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =25
机器人:layout_width =0dip
机器人:文字=地址/>
<的EditText
机器人:ID =@ + ID /地址
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =75
机器人:layout_width =0dip/>
<的TextView
机器人:ID =@ + ID / cityLabel
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:layout_width =0dip
机器人:文字=城市/>
<的EditText
机器人:ID =@ + ID /城
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =25
机器人:layout_width =0dip/>
<的TextView
机器人:ID =@ + ID / stateLabel
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:layout_width =0dip
机器人:文字=国家/>
<的EditText
机器人:ID =@ + ID /状态
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =20
机器人:layout_width =0dip/>
<的TextView
机器人:ID =@ + ID / zipLabel
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:layout_width =0dip
机器人:文字=邮编/>
<的EditText
机器人:ID =@ + ID / ZIP
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =25
机器人:layout_width =0dip/>
< / LinearLayout中>


解决方案

您必须使用嵌套的LinearLayout 的做到这一点。我觉得像这样

<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:ID =@ + ID / custLabel
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =25
            机器人:文字=名称/>        <的EditText
            机器人:ID =@ + ID /客户
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            75:机器人layout_weight = />
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:ID =@ + ID / addressLabel
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =25
            机器人:文字=地址/>        <的EditText
            机器人:ID =@ + ID /地址
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            75:机器人layout_weight = />
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:ID =@ + ID / cityLabel
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:文字=城市/>        <的EditText
            机器人:ID =@ + ID /城
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            25:机器人layout_weight = />        <的TextView
            机器人:ID =@ + ID / stateLabel
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:文字=国家/>        <的EditText
            机器人:ID =@ + ID /状态
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            20:机器人layout_weight = />        <的TextView
            机器人:ID =@ + ID / zipLabel
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:文字=邮编/>        <的EditText
            机器人:ID =@ + ID / ZIP
            机器人:layout_width =0dip
            机器人:layout_height =WRAP_CONTENT
            20:机器人layout_weight = />
    < / LinearLayout中>
< / LinearLayout中>

应该工作。

I have an activity designed to get customer information. First line gets name, 2nd line street address, third line is city, state and zip. I can achieve what I want using a RelativeLayout and by using android:layout_below and android:layout_toRightOf, but then i have to specifically indicate a width for my views. That width may look odd as the user reorients or switches between older and newer versions of android where everything is sized differently. I want to utilize the weight feature of a LinearLayout, but everything just comes up all on one line. How do I insert a line break to create rows of views within a LinearLayout?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/custLabel"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:layout_width="0dip"  
android:text="Name"/>
<EditText
android:id="@+id/customer"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:layout_width="0dip"/>
<TextView
android:id="@+id/addressLabel"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:layout_width="0dip"
android:text="Address"/>
<EditText
android:id="@+id/address"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:layout_width="0dip"/>
<TextView
android:id="@+id/cityLabel"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_width="0dip"
android:text="City"/>
<EditText
android:id="@+id/city"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:layout_width="0dip"/>
<TextView
android:id="@+id/stateLabel"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_width="0dip"
android:text="State"/>
<EditText
android:id="@+id/state"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:layout_width="0dip"/>
<TextView
android:id="@+id/zipLabel"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_width="0dip"
android:text="Zip"/>
<EditText
android:id="@+id/zip"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:layout_width="0dip"/>
</LinearLayout>

解决方案

You must use nested LinearLayout's to do this. I think something like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/custLabel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="Name" />

        <EditText
            android:id="@+id/customer"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".75" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/addressLabel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="Address" />

        <EditText
            android:id="@+id/address"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".75" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/cityLabel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".1"
            android:text="City" />

        <EditText
            android:id="@+id/city"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".25" />

        <TextView
            android:id="@+id/stateLabel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".1"
            android:text="State" />

        <EditText
            android:id="@+id/state"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".20" />

        <TextView
            android:id="@+id/zipLabel"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".1"
            android:text="Zip" />

        <EditText
            android:id="@+id/zip"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".20" />
    </LinearLayout>
</LinearLayout>

should work.

这篇关于Android版的LinearLayout换行符XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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