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

how to fit layout width inside of a horizontalscrollview?

我想水平调整 LinearLayout 的宽度,但它的末尾有一些空白 space(见图)Picture

这是我的代码:

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>

我如何更改此代码以使其末尾没有空白 space?

终于得到答案,我必须在父 linear_layout 中将重力属性声明为 center_horizontal。