点按预览缩略图可查看高分辨率图像

时间:2013-02-03 13:00:30

标签: android menu zoom imagebutton

我是一个新的Android开发人员,我正在尝试为Android创建一个Android应用程序,其中将显示菜单项以及描述成本和图像。 我已经实现了List活动来显示列表中的项目。我制作了一个图像按钮,它将以缩略图显示图像。我希望能够在点击图像按钮时查看缩略图的高分辨率图像。我已经实现了一个onClickListener来监听tap事件,但我不知道哪些方法会让图像缩小。

我已关注this link

但理解起来却很模糊。 Animator类不存在。有人能指导我吗?

1 个答案:

答案 0 :(得分:0)

I found the solution after searching for almost a week.
I used PopupWindow Class for the purpose
Following is the Java Code.

PopupWin.java
public class PopupWin extends Activity{

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            final Button bPopup = (Button)findViewById(R.id.openpopup);
            bPopup.setOnClickListener(new Button.OnClickListener(){

       @Override
       public void onClick(View arg0) {
        LayoutInflater layoutInflater 
         = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        View popupView = layoutInflater.inflate(R.layout.popup, null);  
                 final PopupWindow popupWindow = new PopupWindow(
                   popupView, 
                   LayoutParams.MATCH_PARENT,  
                         LayoutParams.MATCH_PARENT);  

                 Button bDismiss = (Button)popupView.findViewById(R.id.dismiss);
                 bDismiss.setOnClickListener(new Button.OnClickListener(){

         @Override
         public void onClick(View v) {
          // TODO Auto-generated method stub
          popupWindow.dismiss();
         }});

                 popupWindow.showAsDropDown(bPopup, 50, -30);

       }});
        }
    }


popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pop"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/dim_back" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/dim_back"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:orientation="vertical" 
            android:layout_gravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:adjustViewBounds="true"
                android:src="@drawable/appetimg01" />

            <Button
                android:id="@+id/dismiss"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20sp"
                android:text="Go Back"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/appetizerDes1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="0.40"
            android:text="Tap the Image to view High Resolution Image."/>

        <Button
            android:id="@+id/openpopup"
            android:layout_width="80sp"
            android:layout_height="80sp"
            android:layout_gravity="right"
            android:layout_margin="40sp"
            android:background="@drawable/custombutton"
            android:scaleType="centerCrop" />
    </LinearLayout>

</LinearLayout>

The background was appearing white but I wanted it transparent for which I created back_dim.xml in drawables and set it along with android:background="@drawable/back_dim".