gpt4 book ai didi

android - 使相对布局中的两个 TextView 占据 50% 的高度

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:57 27 4
gpt4 key购买 nike

我有一个具有以下项目布局的自定义 ListView :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingBottom="2dip"
android:paddingTop="2dip" >

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:paddingLeft="6dip" />

<TextView
android:id="@android:id/text1"
android:layout_width="50sp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:gravity="center"
android:paddingLeft="6dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />

<TextView
android:id="@+id/start_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@android:id/text1"
android:ellipsize="marquee"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/end_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@id/start_point"
android:layout_toRightOf="@android:id/text1"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

除了 start_pointend_point 的高度不相等外,它显示的大部分与我想要的一样。我尝试了很多东西,但要么以语法错误结束,要么以损坏的布局结束。是否有任何可行的解决方案来实现这一目标?

最佳答案

It shows mostly like I want except that start_point and end_point are not equal in height. I have tried many things but ended either in syntax error or in broken layout. Is there any working solution to achieve that?

像这样在布局中的两个 TextViews 之前插入一个额外的 View ,它将充当为 TextViews 提供等量空间的 anchor :

<RelativeLayout>
// the icon and the first TextView here

<View android:id="@+id/anchor" android:layout_centerVertical="true" android:layout_alignParentRight="true"
android:layout_width="2dp"
android:layout_height="0dp"/>

// the two TextView below it
<TextView
android:id="@+id/start_point" android:layout_above="@id/anchor" // the rest of the attributes />

<TextView
android:id="@+id/end_point" android:layout_below="@id/anchor" // the rest of the attributes />
</RelativeLayout>

关于android - 使相对布局中的两个 TextView 占据 50% 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13780288/

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