【问题标题】:TextView doesn't show in RelativeLayoutTextView 不显示在 RelativeLayout
【发布时间】:2015-02-23 18:58:03
【问题描述】:

我有一个正常工作的TextView,但如果我尝试在RelativeLayout 中显示TextView,它不会显示。(“//本节开始和结束”)

我的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>

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

谢谢...

【问题讨论】:

  • 对于文本视图,尝试将宽度和高度设置为match_parent。看看会发生什么
  • 在Relativelayout中添加android:layout_below="@id/itemSimpleJelly"
  • @Ranjith 似乎RelativeLayout 在自定义视图内,ID 为itemSimpleJelly

标签: android xml textview android-relativelayout


【解决方案1】:

您的RelativeLayout 有一个height25dp 和一个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-->

【讨论】:

    【解决方案2】:

    您不能为您的RelativeLayout 使用这些高度和宽度值,并且有一个简单的解释:您将25dp 用于RelativeLayoutheight20dp 用于padding-bottom5dp 对于文本大小为 17dpTextView 来说是不够的。现在决定权在你。您可以从RelativeLayout 中删除填充底部或增加他的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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2014-07-20
      相关资源
      最近更新 更多