如何通过单击的ImageButton显示全屏图像 [英] how to display fullscreen image by clicking imagebutton
问题描述
我只是在含两张图片这是在绘制文件夹我的布局两个图像按钮。我想要的是,当用户点击图像按钮,他应该看到全屏图像,应该能够放大为好。
这是我的xml:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:weightSum =2>
<的ImageButton
机器人:ID =@ + ID / imageButton1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ piq1
机器人:layout_weight =1
/><的ImageButton
机器人:ID =@ + ID / imageButton2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ piq2
机器人:layout_weight =1/>< / LinearLayout中>
当点击它应该全屏显示和用户的完整图像的图像按钮应能够放大它。请帮我code表示。
我的Java是这样的:
进口android.app.Activity;
进口android.os.Bundle;公共类PIQ延伸活动{@覆盖
保护无效的onCreate(捆绑savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.piq);
}
首先,它只有一个想法,你可以和它需要你弄脏你的手与此code来处理它作为您的情况需要,希望这对你有所帮助,
在这里,用完整的图像和变焦功能,您可以使用它的教程
<一个href=\"http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/\" rel=\"nofollow\">http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/
在这里的布局将
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /布局
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:weightSum =2&GT;&LT;的ImageButton
机器人:ID =@ + ID / imageButton1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:SRC =@机器人:可绘制/ btn_radio/&GT;&LT;的ImageButton
机器人:ID =@ + ID / imageButton2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:SRC =@绘制/ ic_launcher/&GT;&LT; / LinearLayout中&GT;
和这里的code你会使用
最后的ImageButton IMG1 =(的ImageButton)findViewById(R.id.imageButton1);
最终的ImageButton IMG2 =(的ImageButton)findViewById(R.id.imageButton2); 最终的LinearLayout布局=(的LinearLayout)findViewById(R.id.layout); img1.setOnClickListener(新OnClickListener(){ @燮pressLint(NewApi)
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根 layout.setBackground(img1.getDrawable()); }
}); img2.setOnClickListener(新OnClickListener(){ @燮pressLint(NewApi)
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
layout.setBackground(img2.getDrawable());
}
});
i just have two image buttons in my layout containing two pictures which are in drawable folder. all i want is when the user clicks the image button he should see the full screen image and should be able to zoom as well.
this is my xml:
<?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"
android:weightSum="2" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/piq1"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/piq2"
android:layout_weight="1"/>
</LinearLayout>
when the image button in clicked it should display the full image in full screen and user should be able to zoom it. please help me with the code for that.
my java looks like:
import android.app.Activity;
import android.os.Bundle;
public class Piq extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.piq);
}
first of all , its only one idea you can make and it need you dirty your hand with this code to handle it as your case need , hope it helpful for you ,
here the tutorial that using full image and zooming feature you can using it
here the layout will be
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@android:drawable/btn_radio" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
and here the code you will use
final ImageButton img1 = (ImageButton) findViewById(R.id.imageButton1);
final ImageButton img2 = (ImageButton) findViewById(R.id.imageButton2);
final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
img1.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
layout.setBackground(img1.getDrawable());
}
});
img2.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
layout.setBackground(img2.getDrawable());
}
});
这篇关于如何通过单击的ImageButton显示全屏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!