2017-10-20 1 views
0

내가 TableLayout1img1 누를 같은 시간에 hidding TableLayout2를 보여주는 응용 프로그램을 구축하기 위해 노력하고있어,하지만 메신저는 여전히 오류가 발생했습니다를 ... TableLayout을 숨겨진 다른 TableLayout을 표시하는 방법 내 자바 코드 :</p> <p>이이 일에 온 클릭

public class Info extends ActionBarActivity { 
ImageView img1; 
TableLayout tl, tl2; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_info); 
     tl = (TableLayout)findViewById(R.id.infolayout); 
     tl2 = (TableLayout)findViewById(R.id.trueident); 
     img1 = (ImageView)findViewById(R.id.imageView1); 


     img1.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       tl.setVisibility(View.INVISIBLE); 
       tl2.setVisibility(View.VISIBLE); 

      } 
     }); 

    } 


} 

그래서 요점은 내가 숨겨진 trueident 레이아웃을 보여 원하고, 처음부터 infolayout 사람이 보이지 숨길 수있다.

가능합니까? 또한, 이 눌려 졌을 때 반대를 수행하려면 if 코드를 작성해야합니까?

미리 감사드립니다.

답변

0

모두 정상적으로 작동합니다. 파일을 확인하고 비교하십시오. 또한 "안드로이드 모니터"가 말하는 것을 여기에 제공하십시오.

내 코드 :

package com.example.android.myapplication; 

import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.view.View; 
import android.widget.ImageView; 
import android.widget.TableLayout; 

public class Info extends ActionBarActivity { 
    ImageView img1; 
    TableLayout tl, tl2; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    tl = (TableLayout)findViewById(R.id.infolayout); 
    tl2 = (TableLayout)findViewById(R.id.trueident); 
    img1 = (ImageView)findViewById(R.id.imageView1); 

    img1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 

      tl.setVisibility(View.INVISIBLE); 
      tl2.setVisibility(View.VISIBLE); 

     } 
    }); 

} 


} 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.android.myapplication.Info" 
android:id="@+id/activity_info" 
> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="264dp" 
    app:srcCompat="@mipmap/ic_launcher" 
    tools:layout_editor_absoluteX="130dp" 
    tools:layout_editor_absoluteY="135dp" /> 

<TableLayout 
    android:id="@+id/infolayout" 
    android:layout_width="193dp" 
    android:layout_height="107dp" 
    android:background="@color/colorAccent"> 
</TableLayout> 

<TableLayout 
    android:id="@+id/trueident" 
    android:layout_width="match_parent" 
    android:layout_height="103dp" 
    android:background="@color/colorPrimary" 
    > 
</TableLayout> 

</TableLayout> 

manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.android.myapplication"> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".Info"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application>