- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 ScrollView 中实现了一个viewpager,但是每当它到达屏幕的底部边缘时,viewpager就会变得畸形,从而导致 ScrollView 无法工作并且viewpager底部的元素不会显示。这是我的代码:
1. Main Acitivity
public class MainActivity extends AppCompatActivity {
ViewPager viewPager;
ViewPager viewPager2;
PagerAdapter adapter2;
private static int currentPage = 0;
private int[] IMAGES = {R.drawable.one, R.drawable.two, R.drawable.three, R.drawable.four};
private ArrayList<Integer> IMAGESArray = new ArrayList<Integer>();
private ScrollView scrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.landing_page);
scrollView = (ScrollView) findViewById(R.id.scroll);
viewPager2 = (ViewPager) findViewById(R.id.pager3);
// Pass results to ViewPagerAdapter Class
adapter2 = new FirstViewPagerAdapter(TestActivity.this);
// Binds the Adapter to the ViewPager
viewPager2.setAdapter(adapter2);
init();
}
private void init() {
for(int i=0;i<IMAGES.length;i++)
IMAGESArray.add(IMAGES[i]);
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new SecondViewPagerAdapter(TestActivity.this, IMAGESArray));
CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator);
indicator.setViewPager(viewPager);
// Auto start of viewpager
final Handler handler = new Handler();
final Runnable Update = new Runnable() {
public void run() {
if (currentPage == IMAGES.length) {
currentPage = 0;
}
viewPager.setCurrentItem(currentPage++, true);
}
};
Timer swipeTimer = new Timer();
swipeTimer.schedule(new TimerTask() {
@Override
public void run() {
handler.post(Update);
}
}, 2500, 2500);
}
}
2. The first view pager adapter
public class FirstViewPagerAdapter extends PagerAdapter {
private Context mContext;
private ViewPager pager=null;
private int images [] = {R.drawable.whiskey, R.drawable.vodka, R.drawable.whiskey, R.drawable.vodka, R.drawable.whiskey};
public FirstViewPagerAdapter(Context context) {
mContext = context;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View itemView = inflater.inflate(R.layout.page, container, false);
ImageView image1 = (ImageView)itemView.findViewById(R.id.image);
image1.setImageResource(images[position]);
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object) {
container.removeView((View)object);
}
@Override
public int getCount() {
return(5);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return(view == object);
}
}
3. The second view pager adapter
public class SecondViewPagerAdapter extends PagerAdapter {
private ArrayList<Integer> images;
private LayoutInflater inflater;
private Context context;
public SecondViewPagerAdapter(Context context, ArrayList<Integer> images) {
this.context = context;
this.images=images;
inflater = LayoutInflater.from(context);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return images.size();
}
@Override
public Object instantiateItem(ViewGroup view, int position) {
View myImageLayout = inflater.inflate(R.layout.view_pager_item, view, false);
ImageView myImage = (ImageView) myImageLayout.findViewById(R.id.flag);
myImage.setImageResource(images.get(position));
view.addView(myImageLayout, 0);
return myImageLayout;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}}
4. landing_page xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="match_parent"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:background="#cccccc"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:vpi="http://schemas.android.com/tools"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:background="#cccccc"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true" />
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="200dp"
android:layout_gravity="center"
android:gravity="center"
app:ci_drawable="@drawable/myindicator"
vpi:snap="true"/>
</RelativeLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:src="@drawable/hdspiritsz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="7dp"/>
<ImageView android:layout_width="match_parent"
android:src="@drawable/hdextrasz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="7dp"
android:layout_marginLeft="4dp"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="match_parent"
android:src="@drawable/hdspiritsz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="7dp"/>
<ImageView android:layout_width="match_parent"
android:src="@drawable/hdextrasz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="7dp"
android:layout_marginLeft="4dp"/>
</LinearLayout>
<RelativeLayout android:layout_width="match_parent"
android:background="#cccccc"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="@+id/pager3"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="match_parent"
android:src="@drawable/hdspiritsz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="7dp"/>
<ImageView android:layout_width="match_parent"
android:src="@drawable/hdextrasz"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginRight="7dp"
android:layout_marginLeft="4dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
最佳答案
将 android:fillViewport="true"添加到 ScrollView 元素。
关于java - ViewPager ScrollView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44279482/
我目前面临将 ViewPager 放入另一个 ViewPager 中的问题,两者都可滑动。我成功创建了我的第一个 ViewPager,它包含三个页面,中间一个是第二个(内部)ViewPager,其中包
在我的主要 Activity 中,我有一个水平 viewpager。在 viewpager 的一个 fragment 中,我有另一个垂直 viewpager。两者都很好。但是对于水平 viewpage
我想创建一个 ViewPager(包含三个项目),其中每个 View 都是另一个 ViewPager(包含两个项目)。用户然后像这样滑动项目: ViewPager1[0] ViewPager2[0]
如何修复这个错误 setupWithViewPager(android.support.v4.view.ViewPager) in TabLayout cannot br applied to (an
我有一个包含 3 张图片的数组的 viewPage,我想在缩放其中一张时锁定 viewPager,因为当我在右侧滚动时,会出现下一张照片!这是我的代码 enter code here public
我是第一次实现 ViewPager,我遇到了一些问题,因为我收到以下错误: 06-20 10:40:51.366 11377-11377/com.example.ruelas.elite E/Andr
我真的是 android 的新手,如果对我的类(class)作业有任何帮助,我将不胜感激。 我需要做的: 1) 在一个 Activity 中有两个 ViewPagers(未嵌套) 2)两个ViewPa
我正在自定义我的 Android 应用程序以在四个方向上滑动,我正在使用 ViewPager 水平 和 VerticalViewPager 滑动垂直滑动(这就像对 DirectionalViewPag
我需要为平板电脑创建一个 ViewPager,在平板电脑的左侧会有导航按钮供用户选择。例如。 左侧导航将有 4 个图像按钮,每个项目将用户带到不同的教程。每个图像按钮都会加载一个 ViewPager。
我用过Vertical Viewpager在我的显示数据集合的项目中。在单个数据(项目)中,我有更多图像要显示。所以我尝试使用 viewpager。 但是当我水平滚动时,它会阻止垂直 Viewpage
我有一个父级 ViewPager,它的每个页面都包含一个子级 ViewPager。子 ViewPager 可能包含一个 ListView 或一个垂直的 ScrollView。我想将子级 ViewPag
我的任务是创建一个非常不正统的布局,只能通过另一个 viewpager 的第二个 Pane 内的 viewpager 来完成,幸运的是外部 viewpager 需要被锁定所以任务更现实一些,但是意外的
目标是根据屏幕方向(纵向或横向)以不同的布局在屏幕上显示两个 fragment ( fragment A、 fragment B)。 当设备处于纵向模式时,一次仅显示 Frag A 和 Frag B
我想禁用父 viewpager 中的子 viewpager 的滑动。 我目前使用这个自定义子 viewpager public class CustomViewPager extends ViewPa
我有两个 ViewPager - 一个在另一个下面。现在客户希望我们添加扩展底部 ViewPager(具有三个 ListView)以覆盖顶部 ViewPager 的可能性。当我将两个 ViewPage
我用谷歌搜索了这个问题很多天。找到一个解决方案,在Viewpager的开头和结尾添加一个空白View。当viewpager.getcurrentItem()==0时,则重新指向1。在我看来这种做法非常
我从适配器设置标题后,标题未出现在 PagerTabStrip 中 这是我的 Activity public class MainActivity extends AppCompatActivity
我有一个 ViewPager,其中包含多个 TextView,它们具有不同的字体大小。此外,我还获得了增加/减少字体大小的按钮,通过添加其默认大小加上一个名为 STEP 的值(该值通过 inc/dec
我有一个嵌套的 ViewPager,效果非常好。唯一的问题是,一旦子 ViewPager 位于最后一项并且我进一步滚动,父 ViewPager 就会滚动。我不想要这种行为。 我如何实现这一目标? 这是
我想显示一个带有滑动抽屉的 Viewpager。Viewpager 用于滚动图像,我想在该 viewpager 的顶部放置一个滑动抽屉(从顶部到按钮)。 我附上了我的示例代码。如果您对如何实现此屏幕有
我是一名优秀的程序员,十分优秀!