如何在Android中使用ScrollView通过垂直滚动左右滑动
我在滚动视图中有一些布局。这些布局必须可以在左右方向上滑动,但这会与滚动视图产生一些冲突。如何在Android中使用ScrollView同时使用滑动和滚动。我不想使用ViewPager 请帮帮我,因为我对安卓系统比较熟悉如何在Android中使用ScrollView通过垂直滚动左右滑动,android,Android,我在滚动视图中有一些布局。这些布局必须可以在左右方向上滑动,但这会与滚动视图产生一些冲突。如何在Android中使用ScrollView同时使用滑动和滚动。我不想使用ViewPager 请帮帮我,因为我对安卓系统比较熟悉 提前感谢。使用水平滚动视图,它在您的家长滚动视图中左右滚动 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="your_
提前感谢。使用
水平滚动视图
,它在您的家长滚动视图
中左右滚动
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height" >
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height">
</HorizontalScrollView>
</ScrollView>
使用
水平滚动视图
,该视图在父视图内左右滚动滚动视图
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height" >
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height">
</HorizontalScrollView>
</ScrollView>
您可以使用
水平滚动视图
水平滚动您的子视图
,并将此水平滚动视图
放在滚动视图
内。还可以将LinearLayout
与Vertical
方向一起添加为ScrollView
的直接子级
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height" >
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height">
</HorizontalScrollView>
</ScrollView>
下面是一个工作示例。试试这个:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- First row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Second row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Third row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
输出:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- First row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Second row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Third row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
希望这会有所帮助~您可以使用
水平滚动您的子视图
并将此水平滚动视图
放在滚动视图
内。还可以将LinearLayout
与Vertical
方向一起添加为ScrollView
的直接子级
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height" >
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="your_width" android:layout_height="your_height">
</HorizontalScrollView>
</ScrollView>
下面是一个工作示例。试试这个:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- First row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Second row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Third row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
输出:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- First row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Second row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
<!-- Third row -->
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="One"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Two"/>
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:text="Three"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
希望这会有所帮助~你能发布你的xml文件吗?请看,你能发布你的xml文件吗?请看,很高兴知道:)很高兴知道:)