Android setlayout Sichtbarkeit auf den button klicken

In den folgenden code beim klicken der Schaltfläche, die ich ausblenden möchten, die relative layout rl1 und zeigen rl2 aber meine app stürzt nach unten auf den button klicken.Was mache ich falsch

 <?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="wrap_content"
    >
<RelativeLayout 
android:id="@+id/rl1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/welcome_1">

    <ImageView
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"

        android:paddingTop="360dp"
        android:layout_marginRight="4dp"
        android:src="@drawable/button1" />

     </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rl2"
         android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="invisible"
     android:background="@drawable/menu_2"
        ></RelativeLayout>
     </RelativeLayout>

Java-code

public class mockupsActivity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


 //ImageButton img1 = (ImageButton)findViewById(R.id.button1);
    ImageView img1 =(ImageView)findViewById(R.id.button1);
    img1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
           //your code here
   //      Toast.makeText(TouchpointmockupsActivity.this, "test", Toast.LENGTH_SHORT).show();
            LinearLayout rl1 = (LinearLayout) findViewById(R.id.rl1);
            rl1.setVisibility(View.INVISIBLE);
            LinearLayout rl2 = (LinearLayout) findViewById(R.id.rl2);
            rl2.setVisibility(View.VISIBLE);
        }
    });





}
}
  • Lesen Sie Ihre logcat, es wird Ihnen sagen, was Sie falsch gemacht habe. Oder zumindest es veröffentlichen, damit andere sehen können, den stacktrace. 🙂
InformationsquelleAutor Rajeev | 2012-08-25
Schreibe einen Kommentar