Android的:在一个LinearLayout中创建的两列 [英] Android: creating two columns in a linearlayout

查看:207
本文介绍了Android的:在一个LinearLayout中创建的两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Street" 
            android:layout_gravity="left"/>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="456546546"
            android:layout_gravity="right" />

    </LinearLayout>

</LinearLayout>

我试图创建一个布局具有两列,其中一个的TextView在左侧,另一个在右边。然而,textviews仍然都在左侧

I'm trying to create a layout with two columns, with one textview on the left side and the other on the right side. However, the textviews are still all on the left side.

推荐答案

您应该使用<一个href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight"><$c$c>android:layout_weight属性。下面是一个例子:

You should use android:layout_weight attribute. Here is an example:

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="Street" 
        android:layout_gravity="left"
        android:background="#88FF0000"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="456546546"
        android:layout_gravity="right" 
        android:background="#8800FF00"/>

</LinearLayout>

这篇关于Android的:在一个LinearLayout中创建的两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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