将android按钮放在特定的位置

时间:2014-06-26 05:40:50

标签: android xml

我想将Android按钮1放在Android屏幕的特定位置,但取决于它在不同位置显示的TextView1大小。

我如何将android按钮放在特定的地方

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".InfoActivity" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" 
        android:background="@drawable/backquiz">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/question1"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge" 
                android:background="@drawable/next"/>

    </LinearLayout>
</RelativeLayout>

我需要Next按钮才能显示在Bottom中。

Here is the image

3 个答案:

答案 0 :(得分:2)

使用按钮的相对布局。 here是链接。

答案 1 :(得分:2)

尝试以下代码来解决您的问题

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true" //set this propery to align your button in bottom
                    android:layout_centerHorizontal="true"  //set this propery to align your button in center
                    android:background="@drawable/next"
                    />

    </RelativeLayout>

答案 2 :(得分:1)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".InfoActivity" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/question1"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge" 
                android:background="@drawable/next"
                android:layout_below="@+id/textView1"/>

</RelativeLayout>