java – 在onClick上切换布局的可见性
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 在onClick上切换布局的可见性,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1835字,纯文字阅读大概需要3分钟。
内容图文
![java – 在onClick上切换布局的可见性](/upload/InfoBanner/zyjiaocheng/804/0baf08bf60dd4720ba80f0b8944a2ae6.jpg)
当我点击一个按钮时,我需要设置这个布局,我的java就像:
Layout propLayout = (Layout) findViewById(R.id.properLayout);
public void propsBtn(View view) {
propLayout.setVisiblity(View.Visible);
}
我知道布局线我完全错了!如果有人能告诉我如何正确设置,我将非常感激:)
这是我的XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mainBackGround"
tools:context="com.myapplication2.app.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
...contents...
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/properLayout">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="bottom"
android:padding="8dp">
...contents...
</RelativeLayout>
</LinearLayout>
解决方法:
DerGolem给出了正确的答案,但他删除了它,所以我现在在这里报告:
//First we set visibility value of interested layout either to gone, visible or invisible
android:visibility="gone"
然后在onCreate下写如下:
//specify the button that has to handle visibility
ImageButton properties = (ImageButton) findViewById(R.id.propBtn);
//And the layout we want to change is visibility
final LinearLayout propLayout = (LinearLayout) findViewById(R.id.properLayout);
properties.setOnClickListener
(
new View.OnClickListener()
{
public void onClick(View v)
{
if (propLayout.getVisibility() == View.VISIBLE)
{
propLayout.setVisibility(View.INVISIBLE);
}
else
{
propLayout.setVisibility(View.VISIBLE);
}
}
}
);
内容总结
以上是互联网集市为您收集整理的java – 在onClick上切换布局的可见性全部内容,希望文章能够帮你解决java – 在onClick上切换布局的可见性所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。