[英]how to show image in full screen when pressed?
我正在使用SlidingSplashScreen
庫在圖像之間滑動,並在圖像下方顯示小點,以跟蹤所顯示的圖像。 所以我的問題是當按下時如何全屏顯示圖像? 我已經嘗試了@Haresh Chhelana的以下解決方案,但沒有成功:
public class MainActivity extends Activity {
ImageView imageView;
boolean isImageFitToScreen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isImageFitToScreen) {
isImageFitToScreen=false;
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
imageView.setAdjustViewBounds(true);
}else{
isImageFitToScreen=true;
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
});
}
}
下面是我的代碼,主要活動是:
package com.hodhod.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.chabbal.slidingdotsplash.SlidingSplashView;
public class MainActivity extends AppCompatActivity {
private int[] images = {
R.drawable.escapers,
R.drawable.escapers2,
R.drawable.facebook,
R.drawable.facebook
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SlidingSplashView slidingSplashView = (SlidingSplashView) findViewById(R.id.sliding_splash_view);
slidingSplashView.setImageResources(images);
}
}
那是activity_main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
android:orientation="vertical">
<com.chabbal.slidingdotsplash.SlidingSplashView
android:id="@+id/sliding_splash_view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true">
</com.chabbal.slidingdotsplash.SlidingSplashView>
</RelativeLayout>
您必須在圖像上添加clickListener。 像這樣的東西:
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
inflater = (LayoutInflater)activity.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View itemView = inflater.inflate(R.layout.viewpager_item, container,false);
final ImageView image = (ImageView)itemView.findViewById(R.id.imageView);
DisplayMetrics dis = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dis);
int height = dis.heightPixels;
int width = dis.widthPixels;
image.setMinimumHeight(height);
image.setMinimumWidth(width);
itemView.setOnClickListener(new OnClickListener(){
public void onClick(View v){
// here you can show the image in fullscreen
// First method : use an hidden fullscreen Layout (like the first piece of code you've posted)
// Second method : use an Activity
}
try {
Picasso.with(activity.getApplicationContext())
.load(images[position])
.placeholder(R.mipmap.ic_launcher)
.error(R.mipmap.ic_launcher)
.into(image);
}
catch (Exception ex){
}
container.addView(itemView);
return itemView;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.