如何使用match_parent宽度和自动高度比在android视图上制作图像? 视图必须有一个垂直滚动条,可以让我们看到图像的重置。图片下面有一些按钮。
下面的图表可以说明我想要实现的目标。
--------------
| ||
| image ||
| ||
|-------------
| Buttons |
---------------
答案 0 :(得分:1)
您可以使用视图寻呼机。
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="300dp" />
int[] images={R.drawable.pr1,R.drawable.pr2,R.drawable.pr3,R.drawable.pr4,R.drawable.pr5};
viewPager=(ViewPager)findViewById(R.id.viewpager);
adapter=new CircleViewAdapter(StartScreen.this,images);
viewPager.setAdapter(adapter);
适配器:
public class CircleViewAdapter extends PagerAdapter {
private Context mContext;
LayoutInflater mLayoutInflater;
private int[] mResources;
public CircleViewAdapter(Context context, int[] resources) {
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mResources = resources;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.flipper_item,container,false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.flipimage);
imageView.setImageResource(mResources[position]);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}