gpt4 book ai didi

android - 在主要相对布局中对齐两个相对布局

转载 作者:行者123 更新时间:2023-11-30 02:48:47 25 4
gpt4 key购买 nike

    <RelativeLayout
android:id="@+id/OtherWeatherInfo_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_space"
android:layout_marginLeft="@dimen/margin_space"
android:layout_marginRight="@dimen/margin_space" >

<RelativeLayout
android:id="@+id/OtherWeatherInfo"
android:layout_width="@dimen/weather_space"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:background="@drawable/rect_block" >

<LinearLayout
android:id="@+id/humidityLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/humidityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/str_humidity"
android:textSize="@dimen/weather_size"
android:textStyle="bold" >
</TextView>

<TextView
android:id="@+id/humidityValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/str_no_data"
android:textColor="@color/color_white"
android:textStyle="bold" >
</TextView>
</LinearLayout>
</RelativeLayout>

<RelativeLayout
android:id="@+id/OtherWeatherInfo2"
android:layout_width="@dimen/weather_space"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_toRightOf="@+id/OtherWeatherInfo"
android:background="@drawable/rect_block" >

<LinearLayout
android:id="@+id/visiLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/visiTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/str_visi"
android:textSize="@dimen/weather_size"
android:textStyle="bold" />

<TextView
android:id="@+id/visiValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/str_no_data"
android:textColor="@color/color_white"
android:textStyle="bold" />
</LinearLayout>


</RelativeLayout>
</RelativeLayout>

上面的代码是我写的,实现了下图:enter image description here .但我正在实现的是这个:enter image description here或者这个:enter image description here .

我完全不知道我在这里犯了什么错误??我只是在使用主要的相对布局OtherWeatherInfo_main,我在其中嵌入了两个相关布局来表示两个天气属性。 @dimen/weather_space 是 145 dp。我无法在主布局中将两个相对布局平均对齐。我们将不胜感激。

最佳答案

将两个 RelativeLayouts 包裹在水平方向的 LinearLayout 中,然后为两个 RelativeLayouts 分配相同的权重。

一般来说,是这样的:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weight="0.5" />

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weight="0.5" />

</LinearLayout>

关于android - 在主要相对布局中对齐两个相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com