想在android应用程序的运行时期间使一些视图不可见

前端之家收集整理的这篇文章主要介绍了想在android应用程序的运行时期间使一些视图不可见前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的主要.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dip"
    >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:textColor="@color/mbackground1"
android:gravity="center_horizontal"
android:text="@string/decode_label"
android:padding="5dip" 
/>

<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@color/mbackground2" 
android:textColor="@color/mytextcolor" 
android:padding="5dip"
/>


 <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label"
android:gravity="center_horizontal"
android:textColor="@color/mytextcolor"
android:padding="5dip"
/>

<Button 
android:id="@+id/webbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/web_button"
android:textColor="@color/mytextcolor"
/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label1"
android:gravity="center_horizontal"
android:textColor="@color/mytextcolor"
android:padding="5dip"
/>

<Button 
android:id="@+id/callbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/call_button"
android:textColor="@color/mytextcolor"
/>
<TextView

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label2"
android:gravity="center_horizontal"
android:textColor="@color/mytextcolor"
android:padding="5dip"
/>

<Button 
android:id="@+id/emailbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sendemail_button"
android:textColor="@color/mytextcolor"
/>

</LinearLayout>

我希望基于运行时的输出,它应该只显示一个文本视图和对应于该输出的按钮.我在main.xml文件中定义布局,我也在这个领域.

有谁有想法吗.
提前致谢

解决方法@H_404_11@
我假设你知道如何获得你定义的视图的引用,例如:
Button button = (Button)findViewById(R.id.emailbutton)

您需要为代码中要使用的每个视图定义一个id,就像您对email按钮所做的那样:

android:id="@+id/emailbutton"

要设置您调用的视图的可见性,请执行以下操作:

button.setVisibility(View.GONE);

您可以选择将可见性设置为INVISIBLE和VISIBLE.
然后,您可以随意使用可见性.
INVISIBLE和GONE之间的区别在于GONE完全从布局中移除视图,而INVISIBLE“保存”此视图所占用的空间.

您可以在API示例中看到.

原文链接:https://www.f2er.com/android/316966.html

猜你在找的Android相关文章