我的活动中有 2 个布局,如果从第一个布局单击 ImageView“显示”,则应显示第二个布局,但这里没有发生,已经给出了编码更正但无法解决这个问题这是我的代码
public class About extends Activity {
LinearLayout line1, line2;
ImageView show;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
line1=(LinearLayout) findViewById(R.id.ll1);
line2=(LinearLayout)findViewById(R.id.ll2);
show=(ImageView)findViewById(R.id.ss);
show.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
show.setVisibility(View.VISIBLE);
// TODO Auto-generated method stub
line1.setVisibility(View.VISIBLE);
if (line2.getVisibility() == View.INVISIBLE || line2.getVisibility() == View.GONE) {
line2.setVisibility(View.VISIBLE); }
else {
line2.setVisibility(View.INVISIBLE);
}
}
});
Xml 布局
<RelativeLayout 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/black" >
<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<ImageView
android:id="@+id/ss"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/menu"
android:clickable="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="199dp"
android:layout_height="wrap_content"
android:background="@color/black"
android:layout_toRightOf="@+id/ll1"
android:visibility="gone"
>
<ImageView
android:id="@+id/about"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="@+id/textView1"
android:layout_toLeftOf="@+id/jobs"
android:src="@drawable/about" />
<ImageView
android:id="@+id/jobs"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/jobs" />
<ImageView
android:id="@+id/log"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/log" />
<ImageView
android:id="@+id/home"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/home" />
</LinearLayout>
</RelativeLayout>