android how to add a custom horizontal scrollview

2019-09-15 02:27发布

I am going to developing an application where my 1st page is a list of images. I want it should be better visible. in a horizontal srcollview manner having some good visibility. How can I do that. Plz give me a sample example for better understanding.

Thank you

2条回答
够拽才男人
2楼-- · 2019-09-15 02:54

Take a look at the Gallery widget.

查看更多
太酷不给撩
3楼-- · 2019-09-15 02:54

you can use this,

in XML use horizontalscrollView

<HorizontalScrollView 
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="@+id/hrscroll">
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:id="@+id/scrollview_layout">

</LinearLayout>

</HorizontalScrollView>

java code..

        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
        params.width=110;
        LayoutParams params2 = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
        params2.width=100;
        LinearLayout gall = (LinearLayout) findViewById(R.id.scrollview_layout);
        for(int i=0;i<=5;i++){
        LinearLayout Limages = new LinearLayout(this);
        Limages.setOrientation(LinearLayout.VERTICAL);
        ImageView images = new ImageView(this);
      //  images.setScaleType(ImageView.ScaleType.FIT_CENTER);
        images.setLayoutParams(params2);
        images.setBackgroundResource(R.drawable.imagez);
        Limages.addView(images);
        Limages.setLayoutParams(params);
        gall.addView(Limages);
         }
查看更多
登录 后发表回答