gpt4 book ai didi

android - 如果我使用 .75 和 .25,为什么布局权重不起作用?

转载 作者:行者123 更新时间:2023-11-29 17:27:06 25 4
gpt4 key购买 nike

这是我的 XML:

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

android:weightSum="1">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="8 diciembre, 2015"
android:id="@+id/txtFecha"
android:textAlignment="textEnd"
android:layout_margin="5dp"
android:layout_gravity="right" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_margin="10dp">

<TextView
android:layout_width="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text"
android:id="@+id/txtTituloNot"
android:layout_height="wrap_content"
android:maxHeight="52dp"
android:layout_weight="1" />

<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/feclaabajo"
android:layout_below="@+id/txtTituloNot"
android:scaleType="fitXY"
android:adjustViewBounds="false"
android:layout_weight="1" />

</LinearLayout>

<TextView
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text Medium Text Medium Text Medium Text
Medium Text Medium Text Medium Text Medium Text Medium Text
Medium Text Medium Text Medium Text Medium Text Medium Text
Medium Text Medium Text Medium Text Medium Text Medium Text Medium"
android:id="@+id/txtExtracto"
android:layout_margin="5dp"
android:maxHeight="110dp"
android:layout_height="wrap_content" />

<ImageView
android:layout_width="233dp"
android:layout_height="170dp"
android:id="@+id/imageViewNoticia"
android:src="@drawable/imagenodisponible"
android:soundEffectsEnabled="false"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:layout_marginBottom="7dp" />

</LinearLayout>

但现在我只使用以下代码:

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_margin="10dp">

<TextView
android:layout_width="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text"
android:id="@+id/txtTituloNot"
android:layout_height="wrap_content"
android:maxHeight="52dp"
android:layout_weight="1" />

<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/feclaabajo"
android:layout_below="@+id/txtTituloNot"
android:scaleType="fitXY"
android:adjustViewBounds="false"
android:layout_weight="1" />

</LinearLayout>

如您所见,imageview 和 textview 具有:

android:layout_weight="1"

但这看起来像:

image view 看不到,而 Textview 有 100%

我为 Imageview 设置的任何值都不会改变

现在,如果我更改文本的值,但值介于 0 和 .99 之间( ImageView 但重量为 1):

如果我使用 .75 和 .25,这个工作正常,但如果我设置 3 和 1,它就不起作用我希望能够使用最后一个

最佳答案

您已经定义了一个 weightSumLinearLayout 的 1 个。

通过这样做,您告诉 LinearLayout 子项权重总和的最大权重将为 1,但随后您将两个子项的权重设置为 1,总计为 2。

最简单的解决方案是简单地删除 weightSum 属性,因为在这种情况下它不是必需的,这样您就不必记住要保持同步。

关于android - 如果我使用 .75 和 .25,为什么布局权重不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34272474/

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