简体   繁体   中英

Android LinearLayout button position

I have a linearlayout containing 5 buttons inside a horizontalscrollview. The first button is not showing properly(only half visible) and there is a large empty space after the last one. How can I remove this space and make the first button fully visible?

<HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:id="@+id/horizontalScrollView"
    android:layout_above="@+id/btn_minus_linie"
    android:layout_centerHorizontal="true"
    android:fillViewport="true">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:gravity = "center"
    android:orientation="horizontal"
    android:weightSum="5">

    <Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="*"
    android:id="@+id/buton_ori"
    android:onClick="Ori"
    android:layout_weight="1"
    android:layout_alignParentLeft="true" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="+"
        android:id="@+id/buton_plus"
        android:onClick="Plus"
        android:layout_weight = "1"/>

    <Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="-"
    android:id="@+id/buton_minus"
    android:onClick="Minus"
    android:layout_weight = "1"
    />
<Button
    android:textAllCaps="false"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="det"
    android:id="@+id/buton_det"
    android:onClick="Det"
    android:layout_weight = "1"
    />
<Button
    android:textAllCaps="false"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Inv"
    android:id="@+id/buton_inv"
    android:onClick="Inv"
    android:layout_weight = "1" />
</LinearLayout>

将您的Horizo​​ntalScrollView的宽度更改为match_parent

It is because of

android:layout_gravity="center"

in your LinearLayout . Change it to anything that does not refer horizontal alignment. For example I think you want:

android:layout_gravity="center_vertical"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM