setVisibility(View.VISIBLE)失效 5
我在主页面xml文件中引入一个XML头部文件<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:androi...
我在主页面xml文件中引入一个XML头部文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@drawable/top_background">
<LinearLayout
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:paddingRight="3dp"
android:gravity="center" >
<Button
android:id="@+id/edit_button"
android:layout_width="40dp"
android:layout_height="30dp"
android:gravity="center"
android:background="@drawable/top_button_style"
android:visibility="invisible"
android:textColor="#ffffff"
android:text="编辑" /> ///// 按钮设置为隐藏状态
</LinearLayout>
</RelativeLayout>
按钮设置为隐藏状态
代码中根据需求把button设置为显示
LayoutInflter inflater = LayoutInflater.from(this);
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.top, null);
Button editButton = (Button)layout.findViewById(R.id.edit_button);
layout.setVisibility(View.VISIBLE);
layout.requestLayout();
运行显示无效,求解
ayout.setVisibility(View.VISIBLE); 数据有点急写错了,应该是
editButton.setVisibility(View.VISIBLE); 展开
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@drawable/top_background">
<LinearLayout
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:paddingRight="3dp"
android:gravity="center" >
<Button
android:id="@+id/edit_button"
android:layout_width="40dp"
android:layout_height="30dp"
android:gravity="center"
android:background="@drawable/top_button_style"
android:visibility="invisible"
android:textColor="#ffffff"
android:text="编辑" /> ///// 按钮设置为隐藏状态
</LinearLayout>
</RelativeLayout>
按钮设置为隐藏状态
代码中根据需求把button设置为显示
LayoutInflter inflater = LayoutInflater.from(this);
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.top, null);
Button editButton = (Button)layout.findViewById(R.id.edit_button);
layout.setVisibility(View.VISIBLE);
layout.requestLayout();
运行显示无效,求解
ayout.setVisibility(View.VISIBLE); 数据有点急写错了,应该是
editButton.setVisibility(View.VISIBLE); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询