0

我正在创建一个项目列表,可能以按钮的形式。问题是我基本上想要按钮上的三个文本字段,一个左对齐,一个稍微靠左对齐,然后一个右对齐。我怎么能做那样的事情?

4

2 回答 2

0

您应该将三个 TextView 放在一个 LinearLayout 中(以对齐它们)并在 LinearLayout 上放置一个 onClick 回调。

于 2013-01-02T01:01:20.843 回答
0

这是一个使用包含 3 个文本视图的系统按钮样式的布局。您可以使用 onClick 属性定义单击自定义按钮时要调用的方法。

文件:/res/layout/custom_button.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/buttonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onCustomButtonClick" >

    <TextView
        android:id="@+id/text_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="text 1" />

    <TextView
        android:id="@+id/text_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@id/text_1"
        android:text="text 2" />

    <TextView
        android:id="@+id/text_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="text 3" />

</RelativeLayout>
于 2013-01-02T01:22:27.860 回答