【问题标题】:TextView isn't shown above the Button in more than API 21在超过 API 21 中,TextView 未显示在 Button 上方
【发布时间】:2016-11-24 14:08:57
【问题描述】:

我想在 Button 上方显示一个 TextView,但在 API 21 中,Button 在 TextView 上方。

see image, click here

我尝试了android:elevation,但它给 Textview 造成了阴影,效果不好。

我尝试了android:translationZ="100dip",但没有成功。

我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:layout_margin="10dp">

        <Button
            android:id="@+id/custom_listview_food"
            android:text="@string/main_matrial1"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:padding="10dp"
            android:gravity="center_horizontal"
            android:textSize="16sp"
            android:background="@color/listview_matrial"
            android:layout_marginBottom="5dp"

            />

        <TextView
            android:id="@+id/custom_listview_material1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="material 1"
            android:textColor="@color/white"
            android:textSize="20sp"
            android:layout_alignRight="@id/custom_listview_food"
            android:layout_marginTop="50dp"
            android:layout_marginRight="10dp"
            />
</RelativeLayout>

【问题讨论】:

    标签: android android-layout button textview


    【解决方案1】:

    试试这个,如果你对你想要的屏幕布局设计不满意。我会建议你。

    <TextView
        android:id="@+id/custom_listview_material1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="material 1"
        android:textColor="#000"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_alignRight="@id/custom_listview_food"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        />
    <Button
        android:id="@+id/custom_listview_food"
        android:text="main_matrial1"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:padding="10dp"
        android:gravity="center_horizontal"
        android:textSize="16sp"
        android:layout_below="@+id/custom_listview_material1"
        android:background="@color/colorPrimary"
        android:layout_marginBottom="5dp"
        />
    </RelativeLayout>
    

    【讨论】:

    • 谢谢,但是有了这段代码,他们只是改变了他们的位置。我希望按钮在 TextView 下。请看图片
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多