Horizontal LinearLayout won't match parent when using it under HorizontalScrollView

huangapple 未分类评论47阅读模式
英文:

Horizontal LinearLayout won't match parent when using it under HorizontalScrollView

问题

Sure, here is the translated code section:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.xieon_2.Home_dashboard">

    <LinearLayout
        android:id="@+id/main_vertical_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="30dp">

        <HorizontalScrollView
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_horizontal"
                android:orientation="horizontal">

                <ImageButton
                    android:id="@+id/bedroom_but"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:layout_marginLeft="10dp"
                    android:background="@drawable/round_shape"
                    android:src="@drawable/bedroom_icon" />

                <!-- ... Other ImageButtons ... -->

            </LinearLayout>
        </HorizontalScrollView>

        <!-- ... Other Views ... -->

    </LinearLayout>
</LinearLayout>

Please note that I've only provided the translated XML layout code as requested. If you have any further questions or need assistance with other aspects, feel free to ask.

英文:

I want to create an horizontal scroll view for my app
(I have six buttons needed to be distributed equally), everything
works fine when using smaller display (nexus 6 1440x 2560), but when using bigger display (pixel C 2560x1800) I got some space. I remarked
that LinearLayout width cover only the content even though I'm using
match_parent in android:layout_width

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:context=&quot;com.example.android.xieon_2.Home_dashboard&quot;&gt;

    &lt;LinearLayout
        android:id=&quot;@+id/main_vertical_layout&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        android:orientation=&quot;vertical&quot;
        tools:ignore=&quot;MissingConstraints&quot;
        tools:layout_editor_absoluteX=&quot;0dp&quot;
        tools:layout_editor_absoluteY=&quot;30dp&quot;&gt;

        &lt;HorizontalScrollView
            android:layout_marginTop=&quot;10dp&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;&gt;

            &lt;LinearLayout
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;
                android:gravity=&quot;center_horizontal&quot;
                android:orientation=&quot;horizontal&quot;&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/bedroom_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;10dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/bedroom_icon&quot; /&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/kitchen_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;9dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/kitchen_icon&quot; /&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/living_room_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;9dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/living_room&quot; /&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/kids_room_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;9dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/kids_room_icon&quot; /&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/bathroom_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;9dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/bathroom_icon&quot; /&gt;

                &lt;ImageButton
                    android:id=&quot;@+id/Guestroom_but&quot;
                    android:layout_width=&quot;80dp&quot;
                    android:layout_height=&quot;80dp&quot;
                    android:layout_marginLeft=&quot;9dp&quot;
                    android:background=&quot;@drawable/round_shape&quot;
                    android:src=&quot;@drawable/guest_room&quot; /&gt;

            &lt;/LinearLayout&gt;
        &lt;/HorizontalScrollView&gt;

        &lt;TextView
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:text=&quot;----------------------------------------------------------------&quot;
            android:textColor=&quot;@color/RoyalBlue&quot;
            android:textSize=&quot;20sp&quot; /&gt;

        &lt;Button
            android:id=&quot;@+id/control_but&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_gravity=&quot;center_horizontal&quot;
            android:layout_marginTop=&quot;30dp&quot;
            android:text=&quot;Control&quot; /&gt;

        &lt;RelativeLayout
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_marginTop=&quot;30dp&quot;&gt;

            &lt;ImageView
                android:id=&quot;@+id/temp_icon_2&quot;
                android:layout_width=&quot;50dp&quot;
                android:layout_height=&quot;50dp&quot;
                android:layout_marginLeft=&quot;10dp&quot;
                android:src=&quot;@drawable/temperature_icon&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/temp_val&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_toEndOf=&quot;@+id/temp_icon_2&quot;
                android:text=&quot;26&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;40sp&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/degree_2&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_toEndOf=&quot;@+id/temp_val&quot;
                android:text=&quot;&#176;&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;40sp&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/pcnt&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_alignParentEnd=&quot;true&quot;
                android:layout_marginRight=&quot;10dp&quot;
                android:text=&quot;%&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;40sp&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/hum_val_2&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_toStartOf=&quot;@+id/pcnt&quot;
                android:text=&quot;85&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;40sp&quot; /&gt;

            &lt;ImageView
                android:id=&quot;@+id/humidity_icon_2&quot;
                android:layout_width=&quot;50dp&quot;
                android:layout_height=&quot;50dp&quot;
                android:layout_toStartOf=&quot;@+id/hum_val_2&quot;
                android:src=&quot;@drawable/humidity_icon&quot; /&gt;

        &lt;/RelativeLayout&gt;

        &lt;RelativeLayout
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_marginTop=&quot;50dp&quot;&gt;

            &lt;ImageView
                android:id=&quot;@+id/noise_icon&quot;
                android:layout_width=&quot;70dp&quot;
                android:layout_height=&quot;70dp&quot;
                android:layout_alignParentStart=&quot;true&quot;
                android:layout_alignTop=&quot;@+id/noise_unit&quot;
                android:src=&quot;@drawable/air_quality&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/noise_val&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_centerVertical=&quot;true&quot;
                android:layout_toEndOf=&quot;@+id/noise_icon&quot;
                android:text=&quot;15&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;40sp&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/noise_unit&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_centerVertical=&quot;true&quot;
                android:layout_marginLeft=&quot;5dp&quot;
                android:layout_toEndOf=&quot;@+id/noise_val&quot;
                android:text=&quot;PPM&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;28sp&quot; /&gt;

            &lt;TextView
                android:id=&quot;@+id/security_state&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_alignBottom=&quot;@+id/noise_val&quot;
                android:layout_alignParentEnd=&quot;true&quot;
                android:layout_marginEnd=&quot;12dp&quot;
                android:text=&quot;ON&quot;
                android:textColor=&quot;@color/RoyalBlue&quot;
                android:textSize=&quot;35sp&quot; /&gt;

            &lt;ImageView
                android:id=&quot;@+id/security_icon&quot;
                android:layout_width=&quot;50dp&quot;
                android:layout_height=&quot;50dp&quot;
                android:layout_alignBottom=&quot;@+id/noise_val&quot;
                android:layout_toStartOf=&quot;@+id/security_state&quot;
                android:src=&quot;@drawable/home_security&quot;
                android:layout_marginTop=&quot;10dp&quot;/&gt;
        &lt;/RelativeLayout&gt;
    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;

app with large display

app with small display

huangapple
  • 本文由 发表于 2020年5月4日 05:49:19
  • 转载请务必保留本文链接:https://java.coder-hub.com/61582096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定