zoukankan      html  css  js  c++  java
  • HorizontalScrollView水平滑动

    xml布局

      <HorizontalScrollView
                android:id="@+id/hsv"
                android:layout_width="50dp"
                android:layout_height="40dp"
                android:layout_alignParentLeft="true"
                android:layout_toLeftOf="@+id/iamge_glide"
                android:scrollbars="none"
                android:background="#f0f0f0" >
                
                <LinearLayout  
                android:id="@+id/id_gallery"  
                android:layout_width="wrap_content"  
                android:layout_height="wrap_content"  
                android:layout_gravity="center_vertical"  
                android:orientation="horizontal" />
            </HorizontalScrollView>

    activity代码

      String[] name = new String[] { "推荐", "热点", "娱乐", "科技", "汽车", "体育", "财经",
                "军事", "国际", "时尚", "视屏", "社会" };

      private HorizontalScrollView hsv;

      private LinearLayout mGallery;

      private ArrayList<String> list;

      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

        //把name添加到list集合中

        list = new ArrayList<String>();
              for (int i = 0; i < name.length; i++) {
                list.add(name[i]);

            }  

      //把数据添加到HorizontalScrollView中

      hsv = (HorizontalScrollView) findViewById(R.id.hsv);

      mGallery = (LinearLayout) findViewById(R.id.id_gallery);

         int count=list.size;
              for (int i = 0; i < count; i++) {
                TextView tv=new TextView(getApplicationContext());
                tv.setId(i);
                tv.setPadding(10, 2, 5, 2);
                tv.setText(name[i]);
                mGallery.addView(tv);
            }

    }

  • 相关阅读:
    Python 3基础教程32-正则
    Python 3基础教程31-urllib模块
    Python 3基础教程30-sys模块
    Python 3基础教程29-os模块
    Python 3基础教程28-内置函数
    Python 3基础教程27-字典
    Python 3基础教程26-多行打印
    Python 3基础教程24-读取csv文件
    Python 3基础教程25-异常处理
    Python 3基础教程23-多维列表
  • 原文地址:https://www.cnblogs.com/wbp0818/p/5302059.html
Copyright © 2011-2022 走看看