图像滑块使用视图寻呼机(使用透明工具栏)

时间:2015-10-27 15:36:27

标签: android android-studio android-viewpager android-imageview

我已经使用View Pager通过以下教程创建了一个图像滑块 所以我的问题是我希望我的滑块有一个透明的工具栏 当我点击屏幕时,工具栏将隐藏 这是我的代码和输出(我做的),以及我想要的输出。

  1. 我的活动

    public class viewInfo extends AppCompatActivity{
    private ViewPager viewPager;
    private Toolbar toolbar;
    private CustomSwipeAdapter adapter;
    PhotoViewAttacher mAttacher;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_info);
        toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
        viewPager = (ViewPager) findViewById(R.id.view_pager);
        adapter = new CustomSwipeAdapter(this);
        viewPager.setAdapter(adapter);
    
    
    }
    
    
    public class CustomSwipeAdapter extends PagerAdapter {
        private int[] image_resources = {R.drawable.bsu, R.drawable.gameover2};
        private Context context;
        private LayoutInflater layoutInflater;
    
        public CustomSwipeAdapter(Context context) {
            this.context = context;
        }
    
        @Override
        public int getCount() {
            return image_resources.length;
        }
    
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return (view == (LinearLayout) object);
        }
    
        @Override
        public Object instantiateItem(View container, int position) {
            layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View item_view = layoutInflater.inflate(R.layout.swipe_layout, (ViewGroup) container, false);
            ImageView imageView = (ImageView) item_view.findViewById(R.id.image_view);
            imageView.setPadding(5, 5, 5, 5);
            imageView.setImageResource(image_resources[position]);
            ((ViewGroup) container).addView(item_view);
    
            mAttacher = new PhotoViewAttacher(imageView);
            mAttacher.update();
            return item_view;
        }
    
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((LinearLayout) object);
        }
    }
    

    }

  2. 2.XML(swipe_layout)

     <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:background="#000"
        >
        <ImageView
            android:id="@+id/image_view"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:gravity="center"
            />
    </LinearLayout>
    

    3.XML(我的活动的XML)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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"
        android:background="#FFF"
        android:orientation="vertical"
        tools:context="com.thesis.juandirection.juandirectionfinale.viewInfos.viewInfo">
    
    
        <include
            android:id="@id/app_bar"
            layout="@layout/app_bar" />
    
        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
        </android.support.v4.view.ViewPager>
    
    </LinearLayout>
    

    我想要的是这种效果..
    透明工具栏。
    当用户
    试图将侦听器放到Linearlayout时 点击它将隐藏工具栏的布局,但没有运气。
    enter image description here When i touch the screen, actionbar(transparent) will hide

0 个答案:

没有答案