zoukankan      html  css  js  c++  java
  • HorizontalScrollView水平滚动控件的使用

         HorizontalScrollView控件只是支持水平滚动,而且它只能包含一个控件,通常是在<HorizontalScrollView>标签中定义了一个<LinearLayout>

         标签并且在<LinearLayout>标签中android:orientation属性值设置为horizontal,然后在<LinearLayout>标签中放置多个控件,如果<LinearLayout>标签中的控件所占用的总宽度超出屏幕的宽度,就会出现滚动效果。

    一、建立工程,如图

    二、main.xml中代码

    <?xml version="1.0" encoding="utf-8"?>
    <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item1"
                />
            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item2"
                />
            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item3"
                />
            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item4"
                />
            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item5"
                />
        </LinearLayout>
        
    
    </HorizontalScrollView>
    View Code

    三、MainActivity.java中代码

    package com.study.hscrollview;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        
    }
    View Code

    四、效果图

  • 相关阅读:
    CF 335A(Banana-贪心-priority_queue是大根堆)
    Oracle shutdown immediate无法关闭数据库解决方法
    ORA-02266: unique/primary keys in table referenced by enabled foreign keys
    Linux命令学习总结:date命令
    Linux命令学习总结:pwd命令
    Linux命令学习总结:cd命令
    ORACLE表空间管理维护
    ORACLE 12C新特性——CDB与PDB
    [翻译]当分发数据库增长到25G时如何解决
    The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'
  • 原文地址:https://www.cnblogs.com/kingshow123/p/horizontalscrollview.html
Copyright © 2011-2022 走看看