android開發:點擊縮圖查看大圖

來源:互聯網
上載者:User

標籤:android   c   style   class   blog   http   

android中點擊縮圖查看大圖的方法一般有兩種,一種是想新浪微博list頁面那樣,彈出一個視窗顯示大圖(原activity為背景)。另一種就是直接開啟一個新的activity顯示大圖。

1、第一種方法我們可以使用自訂的AlertDialog來實現,代碼如下:ImageView image=(ImageView)findViewById(R.id.small_image);image.setOnClickListener(new OnClickListener() { // 點擊放大public void onClick(View paramView) {LayoutInflater inflater = LayoutInflater.from(context);View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null); // 載入自訂的布局檔案final AlertDialog dialog = new AlertDialog.Builder(context).create();ImageView img = (ImageView)imgEntryView.findViewById(R.id.large_image);imageDownloader.download("圖片地址",img); // 這個是載入網狀圖片的,可以是自己的圖片設定方法dialog.setView(imgEntryView); // 自訂dialogdialog.show();// 點擊布局檔案(也可以理解為點擊大圖)後關閉dialog,這裡的dialog不需要按鈕imgEntryView.setOnClickListener(new OnClickListener() {public void onClick(View paramView) {dialog.cancel();}});}});對應的布局檔案dialog_photo_entry內容為:<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"   xmlns:android="http://schemas.android.com/apk/res/android">    <ImageView android:layout_height="wrap_content" android:id="@+id/large_image "android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true"></ImageView></RelativeLayout> 2、另外一種開啟一個新的activity的方法相對簡單點,大圖activity代碼如下:public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.dialog_photo_entry);activity = this;Bundle bundle = this.getIntent().getExtras();if(bundle!=null){picName = bundle.getString("picName"); //圖片名}ImageView img = (ImageView)this.findViewById(R.id.large_image );imageDownloader.download( picName,img);Toast toast = Toast.makeText(this, "點擊圖片即可返回",Toast.LENGTH_SHORT);toast.setGravity(Gravity.BOTTOM, 0, 0);toast.show();img.setOnClickListener(new View.OnClickListener() { // 點擊返回public void onClick(View paramView) {activity.finish();}});}對應的布局檔案dialog_photo_entry內容為:<?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"><ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"    android:id="@+id/entry_pic" android:layout_margin="0dip" android:padding="0dip">   <ImageView android:layout_height="wrap_content" android:id="@+id/large_image"        android:layout_marginTop="0dip" android:paddingTop="0dip"            android:adjustViewBounds="true"android:layout_width="fill_parent"></ImageView></ScrollView></LinearLayout>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.