欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示效果

 更新時間:2020年08月28日 09:45:35   作者:Sweety_ykx  
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示的具體代碼,供大家參考,具體內(nèi)容如下

MainActivity:

public class MainActivity extends AppCompatActivity {
 private ImageView imageView;
 private Dialog dialog;
 private ImageView image;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 init();
 
 //小圖的點(diǎn)擊事件(彈出大圖)
 imageView.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  dialog.show();
  }
 });
 
 }
 
 private void init() {
 imageView = (ImageView) findViewById(R.id.image);
 
 //展示在dialog上面的大圖
 dialog = new Dialog(MainActivity.this,R.style.FullActivity);
 
 WindowManager.LayoutParams attributes = getWindow().getAttributes();
 attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
 attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
 dialog.getWindow().setAttributes(attributes);
 
 image = getImageView();
 dialog.setContentView(image);
 
 //大圖的點(diǎn)擊事件(點(diǎn)擊讓他消失)
 image.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  dialog.dismiss();
  }
 });
 
 }
 
 //動態(tài)的ImageView
 private ImageView getImageView(){
 ImageView imageView = new ImageView(this);
 
 //寬高
 imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
 
 //imageView設(shè)置圖片
 @SuppressLint("ResourceType") InputStream is = getResources().openRawResource(R.drawable.lala);
 
 Drawable drawable = BitmapDrawable.createFromStream(is, null);
 imageView.setImageDrawable(drawable);
 
 return imageView;
 }
}

布局文件:

<LinearLayout 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=".MainActivity">
 
 <ImageView
 android:id="@+id/image"
 android:src="@drawable/lala"
 android:layout_centerInParent="true"
 android:layout_width="200dp"
 android:layout_height="200dp" />
 
</LinearLayout>

style:

<style name="FullActivity" parent="AppTheme">
 <item name="windowNoTitle">true</item>
 <item name="android:windowFullscreen">true</item>
</style>

效果圖:

沒點(diǎn)擊:

點(diǎn)擊后:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論