android – 在我的PagerAdapter中制作一个ImageView全屏 – 如何?
作者:互联网
我正在测试一个带有某种画廊的应用程序,我设法使用PagerAdapter创建,但我不能让图像在全屏显示.
以下是一些截图:屏幕上的View1 http://imgur.com/TVvFs2v,从View1过渡到View2 http://imgur.com/h6RhxfN
我想要的是删除白色边框和操作栏,使图像全屏.
这是代码:
SSTest.java
package com.exp.viewpagersstest1;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Menu;
public class SSTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sstest);
ViewPager ssViewPager = (ViewPager) findViewById(R.id.ss_view_pager);
ImageAdapter ssAdapter = new ImageAdapter(this);
ssViewPager.setAdapter(ssAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sstest, menu);
return true;
}
}
ImageAdapter.java
package com.exp.viewpagersstest1;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class ImageAdapter extends PagerAdapter {
Context ssContext;
private int[] ssImages = new int[] { R.drawable.splash1,R.drawable.splash2, R.drawable.splash3 };
ImageAdapter(Context ssContext) {
this.ssContext = ssContext;
}
@Override
public int getCount() {
return ssImages.length;
}
@Override
public boolean isViewFromObject(View ssView, Object ssObject) {
return ssView == ((ImageView) ssObject);
}
@Override
public Object instantiateItem(ViewGroup ssContainer, int ssPosition) {
ImageView ssImageView = new ImageView(ssContext);
// int padding = ssContext.getResources().getDimensionPixelSize(0x7f040002);
ssImageView.setPadding(0, 0, 0, 0);
ssImageView.setScaleType(ImageView.ScaleType.FIT_XY);
ssImageView.setImageResource(ssImages[ssPosition]);
((ViewPager) ssContainer).addView(ssImageView, 0);
return ssImageView;
}
@Override
public void destroyItem(ViewGroup ssContainer, int ssPosition,
Object ssObject) {
((ViewPager) ssContainer).removeView((ImageView) ssObject);
}
}
activity_sstest.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SSTest" >
<android.support.v4.view.ViewPager
android:id="@+id/ss_view_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true" />
</RelativeLayout>
编辑:
答案很完美,只需从xml中删除这些行就可以摆脱白色边框:
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
解决方法:
将活动样式设置为NoActionBar应该可以解决问题.例如,在你的清单中放入以下其中一个:
ActionBarSherlock:
<activity
android:name="com.exp.viewpagersstest1.SSTest"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.NoActionBar" >
</activity>
原生动作栏:
<activity
android:name="lecho.app.campus.activity.PlacePhotoActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen
</activity>
标签:android,layout,android-pageradapter 来源: https://codeday.me/bug/20190709/1408611.html