Android:点击按钮后显示图片

E.M*_*ert 0 android image click onclick button

我正在寻找这个2天.我无法弄清楚如何显示图像(在我的res文件夹中)如何在单击按钮后显示图像?

ρяσ*_*я K 7

活动一:

public class TestbuttontestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn=(Button)findViewById(R.id.widget45);
        btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) { 
             Intent inf=new Intent(TestbuttontestActivity.this,Activityfullscreen.class);

             startActivity(inf);
            }
          });
    }
}
Run Code Online (Sandbox Code Playgroud)

活动二:

public class Activityfullscreen extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calc);
       ImageView img=(ImageView)findViewById(R.id.widget45);
       img.setBackgroundResource(R.drawable.digitallovesaktid);
    }
}
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中:

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".TestbuttontestActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
            android:name="Activityfullscreen"></activity>
    </application>
Run Code Online (Sandbox Code Playgroud)

活动一布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <Button
    android:id="@+id/widget45"
        android:layout_width="fill_parent"
        android:layout_height="120dp"
         />
         <TextView
    android:id="@+id/widget45"
        android:layout_width="fill_parent"
        android:layout_height="120dp"
         />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

活动二布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
  <ImageView
    android:id="@+id/widget45"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

第二种也是最好的方法是使用popupwindow和两个布局一个用于主要活动,另一个用于popupwindow:

private void showpopup()
    {
       LayoutInflater inflater = this.getLayoutInflater();
       View mView= inflater.inflate(R.layout.popup,(ViewGroup)findViewById(R.id.lnparentpopup));
       PopupWindow mPopupWindow = new PopupWindow(mView,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, false);
       mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);

       TextView TV=(TextView)this.findViewById(R.id.txtmain);          
      // TableLayout L1 = (TableLayout)findViewById(R.id.tblntarialview);

       mPopupWindow.showAtLocation(TV, Gravity.CENTER, 45, 0);

     }
Run Code Online (Sandbox Code Playgroud)

当用户按下按钮时,此代码将以全屏显示您的图像,除此之外,请分享您的代码....