TextView 不显示在 RelativeLayout 中
TextView doesn't show in RelativeLayout
我有一个可以正常工作的 TextView
,但是如果我尝试在 RelativeLayout
中显示 TextView
,它不会显示。("//this section begin and end")
我的 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>
如果我想让这段代码工作,我必须为 width
和 RelativeLayout
的 height
定义更多的 space,但我不想。我希望我的 RelativeLayout
与我指定的 width
和 height
相同。
谢谢...
您的 RelativeLayout
的 height
为 25dp
,padding
为 20dp
。意味着文本只剩下 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-->
您不能将这些高度和宽度值用于您的 RelativeLayout
并且有一个简单的解释:您将 25dp
用于 RelativeLayout
的 height
20dp
padding-bottom
。 5dp
对于文本大小为 17dp
的 TextView
是不够的。现在决定权在你。您可以从 RelativeLayout
中删除 padding-bottom 或增加他的 height
或减少 textSize
。我认为删除填充是最好的解决方案:
<RelativeLayout
android:layout_width="90dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:background="#e91e63">
<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>
我有一个可以正常工作的 TextView
,但是如果我尝试在 RelativeLayout
中显示 TextView
,它不会显示。("//this section begin and end")
我的 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>
如果我想让这段代码工作,我必须为 width
和 RelativeLayout
的 height
定义更多的 space,但我不想。我希望我的 RelativeLayout
与我指定的 width
和 height
相同。
谢谢...
您的 RelativeLayout
的 height
为 25dp
,padding
为 20dp
。意味着文本只剩下 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-->
您不能将这些高度和宽度值用于您的 RelativeLayout
并且有一个简单的解释:您将 25dp
用于 RelativeLayout
的 height
20dp
padding-bottom
。 5dp
对于文本大小为 17dp
的 TextView
是不够的。现在决定权在你。您可以从 RelativeLayout
中删除 padding-bottom 或增加他的 height
或减少 textSize
。我认为删除填充是最好的解决方案:
<RelativeLayout
android:layout_width="90dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:background="#e91e63">
<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>