android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示效果
本文實(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)文章
Android下使用TCPDUMP實(shí)現(xiàn)數(shù)據(jù)抓包教程
這篇文章主要介紹了Android下使用TCPDUMP實(shí)現(xiàn)數(shù)據(jù)抓包教程,本文講解使用抓包工具tcpdump抓取數(shù)據(jù),然后使用Wireshark來分析數(shù)據(jù),需要的朋友可以參考下2015-02-02Flutter應(yīng)用程序?qū)崿F(xiàn)隱私屏幕示例解析
這篇文章主要為大家介紹了Flutter應(yīng)用程序?qū)崿F(xiàn)隱私屏幕示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09Android中使用自定義ViewGroup的總結(jié)
本篇文章主要介紹了Android中使用自定義ViewGroup的總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01Android fragment實(shí)現(xiàn)多個頁面切換效果
這篇文章主要為大家詳細(xì)介紹了fragment實(shí)現(xiàn)多個頁面切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04Android中如何實(shí)現(xiàn)清空搜索框的文字
本文主要介紹Android中實(shí)現(xiàn)清空搜索框的文字的方法。項(xiàng)目中的有關(guān)搜索的地方,加上清空文字的功能,目的是為了增加用戶體驗(yàn),使用戶刪除文本更加快捷。需要的朋友一起來看下吧2016-12-12Android應(yīng)用程序中讀寫txt文本文件的基本方法講解
這篇文章主要介紹了Android應(yīng)用程序中讀寫txt文本文件的基本方法講解,基本上依靠context.openFileInput()和context.openFileOutput()兩個方法為主,需要的朋友可以參考下2016-04-04Android Tween動畫之RotateAnimation實(shí)現(xiàn)圖片不停旋轉(zhuǎn)效果實(shí)例介紹
Android中如何使用rotate實(shí)現(xiàn)圖片不停旋轉(zhuǎn)的效果,下面與大家共同分析下Tween動畫的rotate實(shí)現(xiàn)旋轉(zhuǎn)效果,感興趣的朋友可以參考下哈2013-05-05Android Jetpack組件中LiveData的優(yōu)劣
LiveData是Jetpack組件的一部分,更多的時候是搭配ViewModel來使用,相對于Observable,LiveData的最大優(yōu)勢是其具有生命感知的,換句話說,LiveData可以保證只有在組件(?Activity、Fragment、Service)處于活動生命周期狀態(tài)的時候才會更新數(shù)據(jù)2023-04-04Android開發(fā)Jetpack組件Room用例講解
這篇文章主要為大家介紹了Android?Jetpack組件Room的使用案例的詳細(xì)講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02