如何创建包含带有按钮的文本视图的布局

Rog*_*pid 2 android android-layout

如何使用textview两侧的按钮创建布局?这是我到目前为止所得到的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/left_button"
        android:layout_width="72dip"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="left" />

    <TextView
        android:id="@+id/center_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dip"
        android:padding="10dip"
        android:text="textview" />

    <Button
        android:id="@+id/right_button"
        android:layout_width="72dip"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="right" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这里的问题是textview是居中的.我希望textview填充剩下的完整空间.我尝试将其android:layout_width设置为fill_parent并删除android:layout_centerHorizo​​ntal,但它似乎与按钮重叠.

Sun*_*hoo 5

步骤1

您需要在屏幕提示的左侧创建第一个按钮 android:layout_alignParentLeft="true"

第2步

在屏幕右侧创建第二个按钮 android:layout_alignParentRight="true"

步骤3

现在创建TextView,并在第一个按钮的右侧提及它,并提到第二个按钮的左侧

android:layout_toRightOf="@id/left_button"
    android:layout_toLeftOf="@+id/right_button"
Run Code Online (Sandbox Code Playgroud)

XML代码

<?xml version="1.0" encoding="utf-8"?>

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

        <Button
            android:id="@+id/left_button"
            android:layout_width="72dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="left" />

        <Button
            android:id="@+id/right_button"
            android:layout_width="72dip"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="right" />
        <TextView
            android:id="@+id/center_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:layout_toRightOf="@id/left_button"
            android:layout_toLeftOf="@+id/right_button"
            android:padding="10dip"
            android:text="textview" />


    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)