我layout的XML有什么问题呢?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/RED"
tools:context=".MainActivity" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/BLUE"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GREEN"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/YELLOW"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="@string/hello_world"
/>
</RelativeLayout>
</HorizontalScrollView>
</RelativeLayout>
我希望绿色盖掉蓝色,按钮在右下角,或者绿色比蓝色的区域还宽,按钮在右边的屏幕之外,通过左右的滚动条才能拉到。
问题在哪里呢?
[解决办法]
用 linearlayout 就可能解决了,relativelayout 用起来要复杂些。
内容大小超过容器大小才会出现滚动条的。
[解决办法]
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/BLUE"
>
android:background="@color/BLUE"改为 android:background="@color/green"
在 <HorizontalScrollView></HorizontalScrollView>之间多加一个空的
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GREEN"
>