gpt4 book ai didi

android - android relative layout中自定义布局的均分和定位

转载 作者:行者123 更新时间:2023-11-29 19:01:31 24 4
gpt4 key购买 nike

这是我的 previous question 的延续.布局更改如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_70_opacity"
android:weightSum="100"
tools:context="com.dell.eventapp.ui.activity.HomeActivity">

<LinearLayout
android:id="@+id/top_image"
android:layout_width="match_parent"
android:layout_height="@dimen/img_height"
android:background="@drawable/activity_background"
android:contentDescription="@string/top_image"
android:orientation="horizontal"
android:scaleType="centerCrop"
android:weightSum="25">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:paddingBottom="@dimen/margin_8dp"
android:text="@string/cio_summit_monaco_2015"
android:textColor="@android:color/white"
android:textSize="@dimen/large_font" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_image"
android:layout_below="@id/top_image"
android:orientation="vertical"
android:weightSum="65">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="160sp"
android:layout_marginStart="@dimen/margin_20dp"
android:layout_marginTop="@dimen/margin_30dp"
android:orientation="horizontal"
android:weightSum="2">

<TextView
android:id="@+id/agenda"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin_20dp"
android:layout_weight="1"
android:background="@drawable/activity_background"
android:gravity="center|bottom"
android:paddingBottom="@dimen/margin_10dp"
android:text="@string/agenda"
android:textColor="@android:color/white"
android:textSize="@dimen/medium_font" />

<TextView
android:id="@+id/sessions"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin_20dp"
android:layout_weight="1"
android:background="@drawable/activity_background"
android:gravity="center|bottom"
android:paddingBottom="@dimen/margin_10dp"
android:text="@string/sessions"
android:textColor="@android:color/white"
android:textSize="@dimen/medium_font" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="160sp"
android:layout_marginStart="@dimen/margin_20dp"
android:layout_marginTop="@dimen/margin_30dp"
android:orientation="horizontal"
android:weightSum="2">

<TextView
android:id="@+id/speaker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="@dimen/margin_20dp"
android:layout_weight="1"
android:background="@drawable/activity_background"
android:gravity="center|bottom"
android:paddingBottom="@dimen/margin_10dp"
android:text="@string/speakerbio"
android:textColor="@android:color/white"
android:textSize="@dimen/medium_font" />

<TextView
android:id="@+id/venues"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_20dp"
android:layout_weight="1"
android:background="@drawable/activity_background"
android:gravity="center|bottom"
android:layout_gravity="center"
android:paddingBottom="@dimen/margin_10dp"
android:text="@string/venues"
android:textColor="@android:color/white"
android:textSize="@dimen/medium_font" />

</LinearLayout>

</LinearLayout>


<RelativeLayout
android:id="@+id/bottom_image"
android:layout_width="match_parent"
android:layout_height="@dimen/img_height1"
android:layout_alignParentBottom="true"
android:background="@drawable/activity_background"
android:contentDescription="@string/top_image"
android:scaleType="centerCrop"
android:weightSum="10">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:paddingBottom="@dimen/margin_8dp"
android:text="@string/home_content"
android:textColor="@android:color/white"
android:textSize="@dimen/large_font" />

</RelativeLayout>

</RelativeLayout>

在根 Relativelayout 中,我使用了 android:weightSum="100",在顶部 Linearlayout 中,我使用了 android:weightSum="25"。在第二个 LinearLayout 中,我使用了 android:weightSum="65"。在嵌套的 LinearLayout 中,我使用了 android:weightSum="2"。在第三个 LinearLayout 中,我使用了 android:weightSum="2"。在底部 RelativeLayout 中,我使用了 android:weightSum="10"。生成的 UI 如下所示:
UI
使用的自定义布局在顶部和底部的间距不均匀。我如何使用 android:weightsumandroid:layout_weight 来做到这一点?

最佳答案

请看。我希望它对你有用。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/imageview_1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageview_1"
android:gravity="center"
android:text="CIO Summit Monaco 2015"
android:textColor="#000000"
android:textSize="18sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/imageview_2"
android:layout_below="@+id/imageview_1"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageview_11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />


<ImageView
android:id="@+id/imageview_12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageview_21"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />


<ImageView
android:id="@+id/imageview_22"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />


</LinearLayout>
</LinearLayout>

<ImageView
android:id="@+id/imageview_2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#33000000"
android:src="@android:drawable/ic_menu_gallery" />
</RelativeLayout>

关于android - android relative layout中自定义布局的均分和定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48922223/

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