English 中文(简体)
如何在Android中的1个XML文件中设置不同的布局
原标题: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.

提前谢谢。

Layout

Username ! EditTextBox

Password ! EditTextBox

Login ! Register

Button ! Button

我希望我的布局是上面的格式,所以我使用了TabLaout,但在这种情况下,它会导致我的按钮的视图,而且它会拉伸一个按钮而不是另一个按钮,因为EditText大于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:maxLength="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>
最佳回答

我建议你在TableLayout&;然后可以在LinearLayout中设置按钮

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

不可能在一个xml文件中设置多个布局。。。出于同样的原因,安卓拥有布局、布局横向等类型的文件夹系统。。

你能做的是由100rabh解释的。。。通过应用相对布局和填充父设置使布局通用。。。

否则,正如我所解释的,你需要制作2个xml布局文件,并将横向布局放在布局横向文件夹中,从而根据手机的方向自动设置相应的布局。。。

希望这能帮助你。。。

您需要创建两个XML文件:

  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.




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签