我有一个TextView可以正常工作,但是如果我尝试在TextView中显示RelativeLayout则不会显示。(“ //本节的开头和结尾”)

我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/relativeLayoutMain"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <com.gc.materialdesign.views.ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/relativeLayoutContent">

        <RelativeLayout
            android:id="@+id/relativeLayoutContainer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <com.gc.materialdesign.views.LayoutRipple
                android:id="@+id/itemSimple"
                android:layout_width="fill_parent"
                android:layout_height="64dp"
                android:background="#FFF"
                android:clickable="true">

                <!--this section - begin-->
                <RelativeLayout
                    android:layout_width="90dp"
                    android:layout_height="25dp"
                    android:layout_alignParentRight="true"
                    android:background="#e91e63"
                    android:paddingBottom="20dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:gravity="center_horizontal"
                        android:layout_marginRight="7dp"
                        android:text="sample text"
                        android:textColor="#727272"
                        android:textSize="17dp"/>

                </RelativeLayout>
                <!--this section - end-->

            </com.gc.materialdesign.views.LayoutRipple>

        </RelativeLayout>

    </com.gc.materialdesign.views.ScrollView>

    </RelativeLayout>

</LinearLayout>


如果我想让此代码工作,我必须为widthheightRelativeLayout定义更多的空间,但是我不想要。我希望我的RelativeLayout与我指定的widthheight相同。

谢谢...

最佳答案

您的RelativeLayoutheight25dp,而padding20dp。意味着只剩下5dp文本-不足以显示字符。您需要减小padding或增大height

<!--this section - begin-->
<RelativeLayout
    android:layout_width="90dp"
    android:layout_height="25dp"    <--------------------------------
    android:layout_alignParentRight="true"
    android:background="#e91e63"
    android:paddingBottom="20dp">   <--------------------------------

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="center_horizontal"
        android:layout_marginRight="7dp"
        android:text="sample text"
        android:textColor="#727272"
        android:textSize="17dp"/>

</RelativeLayout>
<!--this section - end-->

08-18 08:22
查看更多