在 LinearLayout 中设置重力 – Android

huangapple go评论73阅读模式
英文:

Set gravity in LinearLayout - android

问题

我试图使用RelativeLayout和LinearLayout填充TextView和底部按钮的组合。我在MainActivity中编写了一个序列,将方向从水平更改为垂直,反之亦然。所以基本上我需要将行变成列。

以下是xml文件:

<RelativeLayout 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="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp" >

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="0dp"
    android:paddingTop="40dp"
    android:paddingRight="16dp"
    android:orientation="horizontal"
    android:gravity="top"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textv1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="left"
        android:text="@string/text1" />

    <TextView
        android:id="@+id/textv2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text2" />

    <TextView
        android:id="@+id/textv3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text3" />

    <TextView
        android:id="@+id/textv4"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text4" />

</LinearLayout>

<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textv5"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:text="@string/text5" />

    <TextView
        android:id="@+id/textv6"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text6" />

    <TextView
        android:id="@+id/textv7"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text7" />

    <TextView
        android:id="@+id/textv8"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text8" />

</LinearLayout>

<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="bottom"
    android:foregroundGravity="right"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textv9"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="bottom"
        android:text="@string/text9" />

    <TextView
        android:id="@+id/textv10"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text10" />

    <TextView
        android:id="@+id/textv11"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text11" />

    <TextView
        android:id="@+id/textv12"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="@string/text12" />

</LinearLayout>

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

应该显示如下所示:

在 LinearLayout 中设置重力 – Android

但是它显示成这样:

在 LinearLayout 中设置重力 – Android

在 LinearLayout 中设置重力 – Android

只有中间的行保持在正确的位置,其他行都叠在一起。

英文:

I try to use a combination of RelativeLayout and LinearLayout full of TextViews and a button on the bottom. I write a sequence in MainActivity that change the orientation from horizontal to vertical and vice versa. So basically I had to turn lines in columns.

Here is the xml file:

&lt;RelativeLayout 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;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
android:paddingLeft=&quot;10dp&quot;
android:paddingRight=&quot;10dp&quot; &gt;
&lt;LinearLayout
android:id=&quot;@+id/LinearLayout1&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:paddingLeft=&quot;0dp&quot;
android:paddingTop=&quot;40dp&quot;
android:paddingRight=&quot;16dp&quot;
android:orientation=&quot;horizontal&quot;
android:gravity=&quot;top&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv1&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;left&quot;
android:text=&quot;@string/text1&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv2&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text2&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv3&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text3&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv4&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text4&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/LinearLayout2&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;horizontal&quot;
android:gravity=&quot;center&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv5&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;center&quot;
android:text=&quot;@string/text5&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv6&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text6&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv7&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text7&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv8&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text8&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/LinearLayout3&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;horizontal&quot;
android:gravity=&quot;bottom&quot;
android:foregroundGravity=&quot;right&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv9&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;bottom&quot;
android:text=&quot;@string/text9&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv10&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text10&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/textv11&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text11&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/textv12&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text12&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;Button
android:id=&quot;@+id/button2&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Button&quot;
android:layout_alignParentBottom=&quot;true&quot;/&gt;
&lt;/RelativeLayout&gt;

It should appear like this:

在 LinearLayout 中设置重力 – Android

But it turn like this:

在 LinearLayout 中设置重力 – Android

在 LinearLayout 中设置重力 – Android

Only the center line stay in the right place the others stack on top of each other.

答案1

得分: 0

&lt;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="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:layout_marginTop="40dp"&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="602dp"
        android:orientation="vertical"&gt;

        &lt;LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="match_parent"
            android:layout_height="147dp"
            android:gravity="top"
            android:orientation="horizontal"
            android:paddingLeft="0dp"
            android:paddingTop="40dp"
            android:paddingRight="16dp"
            tools:context=".MainActivity"&gt;

            &lt;TextView
                android:id="@+id/textv1"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="left"
                android:text="@string/text1"
                /&gt;

            &lt;TextView
                android:id="@+id/textv2"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text2"
                /&gt;

            &lt;TextView
                android:id="@+id/textv3"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text3"
                /&gt;

            &lt;TextView
                android:id="@+id/textv4"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text4"
                /&gt;
        &lt;/LinearLayout&gt;

        &lt;LinearLayout
            android:id="@+id/LinearLayout2"
            android:layout_width="393dp"
            android:layout_height="141dp"
            android:gravity="center"
            android:orientation="horizontal"
            tools:context=".MainActivity"&gt;

            &lt;TextView
                android:id="@+id/textv5"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:text="@string/text5"
                /&gt;

            &lt;TextView
                android:id="@+id/textv6"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text6"
                /&gt;

            &lt;TextView
                android:id="@+id/textv7"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text7"
                /&gt;

            &lt;TextView
                android:id="@+id/textv8"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text8"
                /&gt;
        &lt;/LinearLayout&gt;

        &lt;LinearLayout
            android:id="@+id/LinearLayout3"
            android:layout_width="397dp"
            android:layout_height="104dp"
            android:foregroundGravity="right"
            android:gravity="bottom"
            android:orientation="horizontal"
            tools:context=".MainActivity"&gt;

            &lt;TextView
                android:id="@+id/textv9"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="bottom"
                android:text="@string/text9"
                /&gt;

            &lt;TextView
                android:id="@+id/textv10"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text10"
                /&gt;

            &lt;TextView
                android:id="@+id/textv11"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text11"
                /&gt;

            &lt;TextView
                android:id="@+id/textv12"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:text="@string/text12"
                /&gt;
        &lt;/LinearLayout&gt;
    &lt;/LinearLayout&gt;

    &lt;Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_alignParentBottom="true"/&gt;

&lt;/LinearLayout&gt;
英文:

How does this look?
Linear Margin

code:

&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;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
android:orientation=&quot;vertical&quot;
android:paddingLeft=&quot;10dp&quot;
android:paddingRight=&quot;10dp&quot;
android:layout_marginTop=&quot;40dp&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;602dp&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;LinearLayout
android:id=&quot;@+id/LinearLayout1&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;147dp&quot;
android:gravity=&quot;top&quot;
android:orientation=&quot;horizontal&quot;
android:paddingLeft=&quot;0dp&quot;
android:paddingTop=&quot;40dp&quot;
android:paddingRight=&quot;16dp&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv1&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;left&quot;
android:text=&quot;@string/text1&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv2&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text2&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv3&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text3&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv4&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text4&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
android:id=&quot;@+id/LinearLayout2&quot;
android:layout_width=&quot;393dp&quot;
android:layout_height=&quot;141dp&quot;
android:gravity=&quot;center&quot;
android:orientation=&quot;horizontal&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv5&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;center&quot;
android:text=&quot;@string/text5&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv6&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text6&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv7&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text7&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv8&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text8&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
android:id=&quot;@+id/LinearLayout3&quot;
android:layout_width=&quot;397dp&quot;
android:layout_height=&quot;104dp&quot;
android:foregroundGravity=&quot;right&quot;
android:gravity=&quot;bottom&quot;
android:orientation=&quot;horizontal&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv9&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:layout_gravity=&quot;bottom&quot;
android:text=&quot;@string/text9&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv10&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text10&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv11&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text11&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv12&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text12&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
&lt;Button
android:id=&quot;@+id/button2&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Button&quot;
android:layout_alignParentBottom=&quot;true&quot;/&gt;

</LinearLayout>

答案2

得分: 0

如果您希望将这些TextView在一行中均匀间隔,我建议您在每个LinearLayout中使用layout_weight,并将包含TextView的LinearLayout相对排列。
但我真的建议您更改方法。
您设置了TextView的宽度和高度为100dp,但是Android有许多屏幕尺寸,因此它们不一定在许多设备上完全适合,并且在多个布局中使用这么多视图会对性能造成影响,尤其是在低端设备上。

我的建议是使用包含TextView的CardView的RecyclerView,然后在GridLayout中使用RecyclerView。您可以通过RecyclerView内的按钮点击事件来相应地更改TextView的布局。

英文:

If you are the textviews to be evenly spaced in a row I suggest you use layout_weight within each LinearLayout, and arrange the LinearLayouts containing the textviews relative to each other.
But I really suggest changing your approach.
One you set the width and height of textviews to 100dp but Android has many screen sizes so they won't always fit exactly on many devices, and there is a performance hit, using these many views in multiple layout for lower end devices.
My suggestion is use a RecyclerView with CardView containing your TextView then use a GridLayout with the recyclerview. You can change the layout of the TextView accordingly via recyclerview inside onClick for button.

答案3

得分: 0

android:layout_height="match_parent"更改为android:layout_height="wrap_content"LinearLayout中。

<LinearLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="bottom"
        android:foregroundGravity="right"
        tools:context=".MainActivity">
英文:

Change android:layout_height=&quot;match_parent&quot; to android:layout_height=&quot;wrap_content&quot; in LinearLayout.

&lt;LinearLayout
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/LinearLayout3&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;horizontal&quot;
android:gravity=&quot;bottom&quot;
android:foregroundGravity=&quot;right&quot;
tools:context=&quot;.MainActivity&quot;&gt;...

答案4

得分: 0

我通过对主文件进行一些调整来解决了这个问题。以下是添加的代码行:

if (myll3.getOrientation() == LinearLayout.HORIZONTAL)
    myll3.setGravity(Gravity.BOTTOM | Gravity.CENTER);
else if (myll3.getOrientation() == LinearLayout.VERTICAL)
    myll3.setGravity(Gravity.RIGHT | Gravity.CENTER);

同时,我还在 XML 文件中进行了一些更改。以下是最终的 XML 代码:

<RelativeLayout 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="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="0dp"
    android:paddingRight="0dp">

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="0dp"
        android:paddingTop="100dp"
        android:paddingRight="16dp"
        android:orientation="horizontal"
        android:gravity="top"
        tools:context=".MainActivity">

        <TextView
            android:id="@+id/textv1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="@string/text1" />

        <!-- 其他 TextView 的部分 -->

    </LinearLayout>

    <!-- 其他 LinearLayout 的部分 -->

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

感谢您的支持和问题解答。

以下是最终的视图:

水平排列示例:
在 LinearLayout 中设置重力 – Android

垂直排列示例:
在 LinearLayout 中设置重力 – Android

英文:

I manage to solve the problem by twiking the main file with some lines. Here is the added line:

            if(myll3.getOrientation() == LinearLayout.HORIZONTAL)
myll3.setGravity(Gravity.BOTTOM | Gravity.CENTER);
else if(myll3.getOrientation() == LinearLayout.VERTICAL)
myll3.setGravity(Gravity.RIGHT | Gravity.CENTER);

And I made some changes in the xml file too. Here is the final XML code:

&lt;RelativeLayout 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;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
android:paddingLeft=&quot;0dp&quot;
android:paddingRight=&quot;0dp&quot; &gt;
&lt;LinearLayout
android:id=&quot;@+id/LinearLayout1&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:paddingLeft=&quot;0dp&quot;
android:paddingTop=&quot;100dp&quot;
android:paddingRight=&quot;16dp&quot;
android:orientation=&quot;horizontal&quot;
android:gravity=&quot;top&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv1&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text1&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv2&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text2&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv3&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text3&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv4&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text4&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/LinearLayout2&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;horizontal&quot;
android:paddingRight=&quot;10dp&quot;
android:gravity=&quot;center&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv5&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text5&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv6&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text6&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv7&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text7&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv8&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text8&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/LinearLayout3&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;horizontal&quot;
android:paddingBottom=&quot;100dp&quot;
android:paddingTop=&quot;100dp&quot;
android:gravity=&quot;bottom&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textv9&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text9&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv10&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text10&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv11&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text11&quot;
/&gt;
&lt;TextView
android:id=&quot;@+id/textv12&quot;
android:layout_width=&quot;100dp&quot;
android:layout_height=&quot;100dp&quot;
android:text=&quot;@string/text12&quot;
/&gt;
&lt;/LinearLayout&gt;
&lt;Button
android:id=&quot;@+id/button2&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Button&quot;
android:layout_alignParentBottom=&quot;true&quot;/&gt;
&lt;/RelativeLayout&gt;

Thx for your support and your answers.

Here is the final view:-
在 LinearLayout 中设置重力 – Android

在 LinearLayout 中设置重力 – Android

huangapple
  • 本文由 发表于 2020年10月14日 01:35:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64340311.html
匿名

发表评论

匿名网友

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

确定