我在寻找这个为期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. 如何显示图片上的按钮点击按钮在Android小部件
- 4. 图片按钮不可点击 - Android
- 5. 点击图片按钮
- 6. 点击AlertDialog按钮后显示ProgressDialog
- 7. PyQt点击按钮后显示文本
- 8. 按钮点击后显示回调
- 9. 如何在点击按钮后在文本后面显示图片
- 10. 点击按钮时显示图像?
- 11. 按钮点击显示ex.message
- 12. html点击按钮显示/隐藏图片?
- 13. 图片按钮不显示,点击正在工作
- 14. 在按钮上显示图片点击YouTube视频
- 15. JSP - 图片按钮在点击后成为图片
- 16. 点击显示图片JButton
- 17. 上点击显示图片
- 18. javascript点击图片显示
- 19. Android AutoCompleteTextView在无关按钮被点击后显示建议
- 20. Android - 快速点击后,点击按钮的按钮停止
- 21. 在按钮点击后在mvc2中显示图像
- 22. 如何在点击flex按钮后显示图表?
- 23. 在android中按钮单击后显示图像
- 24. 单击后退按钮后,片段无法正确显示
- 25. 隐藏按钮,然后等待2秒后再次显示,点击按钮后
- 26. Android按钮点击
- 27. 网页按钮点击图片更新
- 28. 隐藏图片上的按钮点击
- 29. 如何模拟图片按钮点击
- 30. 无法点击图片按钮
应提供多一点信息:如何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