如何在水平滚动视图中调整布局宽度?



我想水平调整线性布局的宽度,但末端有一些空白(见图(图片

这是我的代码:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shahin.testing2.MainActivity">
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40px"
android:id="@+id/layout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/Linear"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
</HorizontalScrollView>

</LinearLayout>

如何更改此代码,使其末尾没有空格?

最后我得到了答案,我必须在父linear_layout中声明重力属性center_horizontal。

最新更新