gpt4 book ai didi

java - 如何在父元素和 subview 组之间分配空间

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

我想构建一个布局,其中的图像应该占屏幕的 90% 高度,最后 10% 是我在水平布局中拥有的 3 个 TextView ,我可以通过设置dp 中的图像覆盖 90% 的屏幕 (500dp) 我在任何地方都尝试了 layout_weight 并且它无法正常工作是否有任何方法我可以在不显式设置图像高度的情况下实现这一目标 Hers a screenshot! This is my end goal but i have explicitly set image height in this

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:weightSum="2" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="500dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/martin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>

<TextView
android:text="Martin garrix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>

<TextView
android:text="Beleive"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>

<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Imagine!!" />
</LinearLayout>
</LinearLayout>

最佳答案

您必须为图像使用 android:height="0dp"和 android:layout_height="9",为其他容器使用 android:layout_height="1"。 weightSum 也应为 10。您可以查看此示例以获取 layout_weigth http://abhiandroid.com/ui/linear-layout 的示例

   <?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:weightSum="10" >

<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_weight="9"
>

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:srcCompat="@drawable/martin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
>

<TextView
android:text="Martin garrix"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>

<TextView
android:text="Beleive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>

<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Imagine!!" />
</LinearLayout>
</LinearLayout>

关于java - 如何在父元素和 subview 组之间分配空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48975205/

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