ScrollView的学习

来源:互联网 发布:windows蓝牙抓包工具 编辑:程序博客网 时间:2024/06/05 01:52


ScrollView的宽度和高度设置有什区别呢?


  android:layout_width="match_parent"  android:layout_height="match_parent"

截图效果(动态图显示的效果太差,在这里句不显示了):




<?xml version="1.0" encoding="utf-8"?><ScrollView    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:overScrollMode="never"    android:fadingEdge="none"    >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:fitsSystemWindows="true"        android:orientation="vertical"        >        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>    </LinearLayout></ScrollView>



android:layout_width="wrap_content"android:layout_height="wrap_content"


跟上面的效果一样
这样就说明ScrollView的长度和宽度是根据子控件的长度和宽度决定的,ScrollView自己设置宽度和高度不影响显示的效果
另外一个注意的地方就是ScrollView的会限制子空间的“布局”要统一,没有在外层布局中加入ScrollView会显示如下的效果,加入的ScrollView就会全部左边是紫颜色的布局,右边留出一段空白。
<?xml version="1.0" encoding="utf-8"?><LinearLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    xmlns:android="http://schemas.android.com/apk/res/android">        <RelativeLayout            android:layout_width="200dp"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="148dp"            android:background="#6600a1">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_centerVertical="true"                android:layout_marginLeft="10dp"                android:padding="8dp"                android:src="@mipmap/back"                />            <!--<ImageView-->            <!--android:id="@+id/order_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/face"-->            <!--/>-->            <!--<ImageView-->            <!--android:id="@+id/search_back"-->            <!--android:layout_width="wrap_content"-->            <!--android:layout_height="wrap_content"-->            <!--android:layout_centerVertical="true"-->            <!--android:layout_marginLeft="10dp"-->            <!--android:padding="8dp"-->            <!--android:src="@mipmap/back"-->            <!--/>-->            <TextView                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_centerInParent="true"                android:gravity="center"                android:text="选择城市"                android:textColor="#fff"                android:textSize="18sp" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentRight="true"                android:layout_centerInParent="true"                android:layout_marginRight="25dp"                android:src="@mipmap/search_little"                />        </RelativeLayout>    </LinearLayout>



0 0