我怎样才能点击一张图片,并使其像WhatsApp消息一样扩展到全屏?
如果您在WhatsApp中单击图片信息,它将展开并占据整个屏幕。我一直无法弄清楚如何做到这一点,并且迄今为止一直依靠打开占据全屏显示图像的对话框。这只不过是光滑的,但随着在WhatsApp中扩大占用全屏幕的图像。我怎样才能点击一张图片,并使其像WhatsApp消息一样扩展到全屏?
这是我迄今为止的AlertDialog代码。
MainActivity.java
import android.app.Activity; import android.os.Bundle;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Item item1 = new Item("Message 1");
Item item2 = new Item("Message 2");
Item item3 = new Item("Message 3");
Item item4 = new Item("Message 4");
ArrayList<Item> itemsArrayList = new ArrayList<>(); // calls function to get items list
itemsArrayList.add(item1);
itemsArrayList.add(item2);
itemsArrayList.add(item3);
itemsArrayList.add(item4);
CustomAdapter adapter = new CustomAdapter(this, itemsArrayList);
final ListView lv = (ListView) findViewById(R.id.listView);
lv.setAdapter(adapter);
}
}
CustomAdapter.java
import android.app.Dialog; import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
class CustomAdapter extends BaseAdapter {
private Context context;
private ArrayList<Item> items;
public CustomAdapter(Context context, ArrayList<Item> items) {
this.context = context;
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).
inflate(R.layout.list_view_row, parent, false);
}
Item currentItem = (Item) getItem(position);
TextView textViewItemName = (TextView)
convertView.findViewById(R.id.textView1);
final ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
textViewItemName.setText(currentItem.getText());
if (position == 0) {
imageView.setImageResource(R.drawable.a);
} else{
imageView.setImageResource(R.drawable.anime);
}
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Dialog mSplashDialog = new Dialog(CustomAdapter.this.context);
mSplashDialog.setContentView(R.layout.zoom_layout);
ImageView imageView = (ImageView) mSplashDialog.findViewById(R.id.imageViewZoom);
imageView.setImageDrawable(imageView.getDrawable());
mSplashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
mSplashDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
mSplashDialog.show();
}
});
return convertView;
}
}
任何人都可以点我就如何做到这一点,或者提供一些示例代码资源,让我开始?
我试过在这里实施解决方案How to Zoom in/Out an ImageView(not using Canvas) in android,但ImageView已经放大并且不响应点击。此外,我的默认图像尺寸比屏幕大,因此它被切断。
回答:
可以使用的PhotoView库放大/缩小:
1)下方添加到您的模块gradle这个:
compile 'com.commit451:PhotoView:1.2.4'
2)
PhotoViewAttacher photoAttacher; photoAttacher = new PhotoViewAttacher(My_Image);
photoAttacher.update();
如果需要放大全屏幕,然后你可以使用:
解释:setScaleType属性可用于调整图像的大小以匹配ImageView的大小。
myImageView = (ImageView) findViewById(R.id.my_img); myImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isImageFullScreen) {
isImageFullScreen=false;
myImageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
myImageView.setAdjustViewBounds(true);
}else{
isImageFullScreen=true;
myImageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
myImageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
});
回答:
我认为你可以有一个活动的全屏幕图像,并编码过渡动画,所以你得到所需的效果。 看看这个链接,因为它可能是有帮助的。 Android - How to create a transition from an item in listview to a whole activity?
以上是 我怎样才能点击一张图片,并使其像WhatsApp消息一样扩展到全屏? 的全部内容, 来源链接: utcz.com/qa/257749.html