如何在单个按钮视图Android中将两个文本的最末端(左和右)对齐

时间:2019-08-11 10:20:42

标签: android

我有一个按钮,用于显示其他弹出窗口中的项目列表 在该按钮中,我希望文本作为标签左对齐,而在文本右侧则根据从弹出窗口中选择的项目动态添加

如何在单个按钮上对齐这两个文本?我是android新手。

尝试将不同的ascii字符用作空格,但没有帮助

<Button
            android:id="@+id/button"
            android:layout_width="400dp"
            android:layout_height="80dp"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="14dp" />

预期结果

[**Name**                    john] ---- single button view with two texts

enter image description here

1 个答案:

答案 0 :(得分:1)

将您的按钮和文本视图包装在框架布局内,以及高程显示按钮上方的文本视图:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:textAllCaps="false"
        android:textSize="14dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
        android:text="TextView 1"
        android:layout_margin="5dp"
        android:elevation="2dp"
        android:outlineProvider="none"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|end"
        android:text="TextView 2"
        android:layout_margin="5dp"
        android:elevation="2dp"
        android:outlineProvider="none"/>

</FrameLayout>

注意:android:outlineProvider =“ none”将删除高程提供的文本视图上的阴影。

enter image description here