开发者

layout problem in android

i try show layout like image 1 (textView and editText in same line) but my out put shown like image 2 ! i try with this code :

    <?xm开发者_开发问答l version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5px"
    >

    <TextView 
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="URL:"
        android:layout_alignBaseline="@+id/entry"
        android:layout_alignParentLeft="true"/>
        />

    <EditText 
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/label"
        android:layout_alignParentTop="true"
        />

    <Button 
        android:id="@+id/button" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"
        android:paddingRight="30px" 
        android:paddingLeft="30px" 
        android:text="Go..." 
        />

</LinearLayout>

please help me thanks

layout problem in android

layout problem in android


Try this

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="vertical">
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<TextView 
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="URL:"
    android:layout_alignBaseline="@+id/entry"
    android:layout_alignParentLeft="true"/>
    />
<EditText 
    android:id="@+id/entry"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/label"
    android:layout_alignParentTop="true"
    />
</LinearLayout>
<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal"
    android:paddingRight="30px" 
    android:paddingLeft="30px" 
    android:text="Go..." 
    />
</LinearLayout>

Or use RelativeLayout


Use RelativeLayout instead of Linear one and get use of android:rightOf.


As far as I understood, you cannot use such _toRightTop, _BOTTOM attributes with a linear Layout. Use RelativeLayout and all should be fine.


Use relative layout instead of linear layout.One advantage of this is that it improves your performance.if you try to search and id suing a linear layout,it will check with every component of the linear layout and try to match with its id but with relativer layout it will be faster as all elements are defined relative to each other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜