我在寻找这个为期2天。我无法弄清楚如何显示图像(在我的res文件夹中)如何在单击按钮后显示图像?Android:点击按钮后显示图片
回答
活动一:
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);
}
});
}
}
活动二:
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);
}
}
的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>
活动一个布局:
<?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>
活动二布局:
<?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>
和第二和最佳的方式使用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);
}
该代码会显示您的图片在全屏模式下用户按下按钮,你从这个要分开请分享您的代码是什么....
谢谢,我会试试这个。如果我想要全屏显示图像,我必须创建两个活动。我无法用方法显示图像。我是否正确? – 2012-03-04 22:46:48
谢谢,但我想通过使用popupwindow的另一种方法,你可以尝试它,否则我会尝试你... – 2012-03-04 22:50:52
好吧,请注意先有tutorials和Android网站上的文档(如ImageView),以及所有网站上的示例程序。
这answer告诉您如何这样的教程和全屏选项结合起来。
一般,图像被显示在ImageView的。您调用的方法取决于您的图像的可用性:如果您将其作为静态资源添加到项目中,则可以使用setImageResource(int resId)
。如果您已经将它作为位图或绘图下载,请使用相应的setX方法。
希望这会有所帮助。
没有任何方法像setBackground()来显示图像?是观看创建新班级的图像的唯一方式? – 2012-03-04 22:22:28
我还没有尝试过为止,但在View类这样的[方法](http://developer.android.com/reference/android/view/View.html#setBackgroundResource(INT))。但是你应该问问自己,你是否想将某些东西的背景设置为图像并将其放在它上面 - 或者只是想显示简单而简单的图像( - > ImageView) – Patrick 2012-03-04 22:26:32
它显示我的图像,但作为背景,所以我可以看到我的图像上的其他按钮。有什么方法可以显示完整图像而不是背景吗? – 2012-03-04 22:29:36
- 1. 点击图片显示上传按钮
- 2. 如何在点击提交按钮后显示图片?
- 3. 如何在点击3张图片后显示提交按钮?
- 4. 点击浏览器后退按钮时显示图片预览
- 5. 如何显示图片上的按钮点击按钮在Android小部件
- 6. 图片按钮不可点击 - Android
- 7. 点击图片按钮
- 8. JavaScript点击图片按钮
- 9. 点击按钮后显示错误Javascript
- 10. 点击AlertDialog按钮后显示ProgressDialog
- 11. 显示html代码后点击按钮
- 12. 按钮点击后显示回调
- 13. AngularJS:按钮点击后显示html块
- 14. PyQt点击按钮后显示文本
- 15. Android按钮点击显示webView
- 16. 如何在点击按钮后在文本后面显示图片
- 17. 点击图片后显示文字
- 18. Google地图不显示(点击按钮)
- 19. 显示谷歌地图,点击按钮
- 20. 点击按钮时显示图像?
- 21. 显示,当点击按钮
- 22. 按钮点击显示div
- 23. 按钮点击显示ex.message
- 24. 点击按钮显示按钮的值
- 25. 点击图片按钮后恢复原来的颜色android
- 26. 按钮点击显示上传的图片
- 27. html点击按钮显示/隐藏图片?
- 28. 点击按钮,随机图片全屏显示
- 29. 图片按钮不显示,点击正在工作
- 30. 在按钮上显示图片点击YouTube视频
应提供多一点信息:如何d啊,你要显示它,也许包括不使用的代码(部分)... – Patrick 2012-03-04 21:25:11
我想点击一个按钮,我写这View.OnClickListener时间表=新View.OnClickListener后在我的res文件夹显示的图像() {public void onClick(View v){//我不知道我必须在这里写什么?}我怎么能更具体? – 2012-03-04 21:49:05
如果你想显示这将是有益的veery ... ImageView的,在ImageView的一个对话框...;) – Patrick 2012-03-04 21:53:29