文本视图不可见
Text View is not visible
我有一个文本视图,如果满足特定条件,它应该会显示。
其他视图在满足条件时正常运行,但文本视图不可见。
<?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:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:layout_below="@+id/drawerList"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:textStyle="italic"/>
</RelativeLayout>
没有显示 id=hello 的文本视图。
这是我正在使用的代码-
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.GONE);
}
对于 TextView 在声明中添加:
android:visibility="invisible"
你的代码应该是:
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.INVISIBLE);
}
希望这能解决您的问题。
我将您的 xml 加载到 android studio 并且似乎没问题,除了 ID 为 "hello" 的 textview 似乎在布局中被 recyclerview 向下推了。尝试如下加载它,看看它是否有帮助:
<?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:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:paddingLeft="5dp"
android:textStyle="italic"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
还有一点是关于你的情况,尽量保存你的“!”在 s 变量中,然后进行比较。您还使用 Log 语句验证是否满足您的条件。
更改 RecyclerView
和 TextView
属性 - 使 RecyclerView
成为 TextView
的 layout_above
,而不是 [=11= 下面的 TextView
].
此外 layout_alignParentBottom="true"
必须添加到 TextView
。
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello"
android:layout_marginTop="15dp" />
<TextView
android:id="@+id/hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:text="Hello"
android:layout_alignParentBottom="true"
android:textColor="#000"
android:textStyle="italic" />
我有一个文本视图,如果满足特定条件,它应该会显示。 其他视图在满足条件时正常运行,但文本视图不可见。
<?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:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:layout_below="@+id/drawerList"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:textStyle="italic"/>
</RelativeLayout>
没有显示 id=hello 的文本视图。
这是我正在使用的代码-
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.GONE);
}
对于 TextView 在声明中添加:
android:visibility="invisible"
你的代码应该是:
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.INVISIBLE);
}
希望这能解决您的问题。
我将您的 xml 加载到 android studio 并且似乎没问题,除了 ID 为 "hello" 的 textview 似乎在布局中被 recyclerview 向下推了。尝试如下加载它,看看它是否有帮助:
<?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:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:paddingLeft="5dp"
android:textStyle="italic"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
还有一点是关于你的情况,尽量保存你的“!”在 s 变量中,然后进行比较。您还使用 Log 语句验证是否满足您的条件。
更改 RecyclerView
和 TextView
属性 - 使 RecyclerView
成为 TextView
的 layout_above
,而不是 [=11= 下面的 TextView
].
此外 layout_alignParentBottom="true"
必须添加到 TextView
。
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello"
android:layout_marginTop="15dp" />
<TextView
android:id="@+id/hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:text="Hello"
android:layout_alignParentBottom="true"
android:textColor="#000"
android:textStyle="italic" />