开发者

How to set different Layouts in 1 XML file in Android

Hi friends i have set my layout thru TabLayout within LinearLayout but still my button in the end couldn't be set properly as TabLayout divides all the fields in number of columns so can anyone help how to set 2 Layouts in one XML file means all the fields in TabLayout and remaining both Login and Register buttons in Linear Layout ore some other so that they can set properly.

Thanks in advance.

Layout

Username ! EditTextBox

Password ! EditTextBox

Login ! Register

Button ! Button

I want my Layout in above Format so i have used TabLaout but in that case it is causing my button's view as well as it is stretching one button than other one as EditText is larger than TextView

 <?xml 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="fill_parent"
        >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:textSize="26sp"
    android:text="@string/login_text"/>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
    <TableRow>
    <TextView  
        android:layout_width="120px"  
        android:text="User name"
        />
    <EditText
        android:id="@+id/txtUserName"
        android:singleLine="true"
        android:ma开发者_C百科xLength="20"
        android:width="195px"
    />
    </TableRow>
    <TableRow>
    <TextView  
        android:layout_width="120px"  
        android:text="Password"
        />
    <EditText
        android:id="@+id/txtPassword"
        android:width="195px"
        android:maxLength="20"
        android:singleLine="true"
        android:password="true"
    />
    </TableRow>
    <TableRow>
            <TextView />
            <CheckBox android:id="@+id/chkRememberPassword"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Remember Password"
                />   
        </TableRow>
        <TableRow>
        <Button 
                android:id="@+id/buttonRegister" 
                android:text="Register" 
                android:layout_width="124px"
                android:layout_height="wrap_content"
                android:layout_below="@+id/chkRememberPassword"
                android:layout_alignRight="@+id/chkRememberPassword"
                />
        <Button 
            android:id="@+id/buttonSignIn" 
            android:text="Log In" 
            android:layout_width="124px"
            android:layout_height="wrap_content"
            android:layout_below="@+id/chkRememberPassword"
            android:layout_alignLeft="@+id/chkRememberPassword"
            />        
    </TableRow>

    <TextView  
    android:id="@+id/statusError"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     />
    </TableLayout>
    </LinearLayout>


I suggest you to use wrap_content in TableLayout & then you can have your buttons in LinearLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>


Its not possible to set more than one layout in a single xml file... And for the same reason Android has layout, layout-landscape, etc. type of folder system..

What you can do is as explained by 100rabh... Make the layout universal by applying relative layout and fill parent settings...

Otherwise as i explained you need to make 2 xml layout files and place the layout for landscape in the layout-landscape folder thereby the respective layout will automatically be set according to the orientation of the phone...

Hope this helps u...


You need to create 2 XML files:

  1. One in the normal layout folder
  2. A second in a res/layout-land to define the layout for the landscape orientation. You'll need to create the res/layout-land folder if it does not already exist.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜