Android TextView在使用椭圆化时修改线性布局比例
我正在使用ListView显示电影列表。我用android:layout_weight来排列每个项目,我把0.5作为我的RelativeLayout,它包含两个文本视图:ZoneName和FilmName fragment1.xml:Android TextView在使用椭圆化时修改线性布局比例,android,android-layout,listview,android-linearlayout,Android,Android Layout,Listview,Android Linearlayout,我正在使用ListView显示电影列表。我用android:layout_weight来排列每个项目,我把0.5作为我的RelativeLayout,它包含两个文本视图:ZoneName和FilmName fragment1.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:or
<?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:background="@drawable/fond"
>
<TextView
android:text="En séléctionnant un des écrans ci-dessous, vous accéderai à des informations complémentaires sur les contenus qui sont en train de passer à l'écran."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="20dp"
android:id="@+id/secondScreenInformationTextView"
android:textColor="#FFF" />
<ListView
android:id="@+id/lv_select_screen"
android:background="#26FFFFFF"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
这里是我的项目\u选择\u screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/screenTable"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="@+id/item_img_screen_type"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="0.2"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_marginTop="10dp"
>
<TextView
android:id="@+id/item_title_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:textSize="18sp"
android:textColor="#FFF"
android:textStyle="bold" />
<TextView
android:id="@+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_below="@+id/item_title_screen"/>
</RelativeLayout>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="0.2"
android:id="@+id/item_poster_miniature"/>
<ImageView
android:layout_width="15dp"
android:layout_margin="2dp"
android:layout_height="15dp"
android:layout_weight="0.1"
android:src="@drawable/menu_triangle"
android:id="@+id/item_img_triangle_select_screen"
android:layout_gravity="center_vertical"/>
</LinearLayout>
它可以很好地处理短字符串,但我添加了android:maxLines=“1”和android:ellipsize=“end”以在必要时为字符串设置快捷方式。但当它这样做时,它扩展了我的RelativeLayout的宽度,而我的3 imageView似乎缩小了以补偿这种变化
我可以用maxWidth来修复这个问题,但它不再是动态的 是的,这种行为是意料之中的 您正在使用
android:layout_width="wrap_content"
对于您的文本视图
。因此,它将尝试包装其全部内容,并相应地调整其大小
由于内容较大且已省略号化,因此文本视图采用可用的最大宽度来包装其所有内容,然后在最后省略号化
因此,解决方案是,
1) 文本视图的宽度是固定的,末尾是椭圆
2) 或者通过编程将内容截断到完美布局渲染所需的长度。还可以向截断的字符串添加省略号
两者都会产生相同的效果(这是您的选择),但是不会扭曲您的布局是的,这种行为是意料之中的 您正在使用
android:layout_width="wrap_content"
对于您的文本视图
。因此,它将尝试包装其全部内容,并相应地调整其大小
由于内容较大且已省略号化,因此文本视图采用可用的最大宽度来包装其所有内容,然后在最后省略号化
因此,解决方案是,
1) 文本视图的宽度是固定的,末尾是椭圆
2) 或者通过编程将内容截断到完美布局渲染所需的长度。还可以向截断的字符串添加省略号
两者都有相同的效果(由您选择),但绝不会扭曲您的布局当您处理重量时,始终根据
方向为孩子提供0dp
作为高度或宽度,并让重量进行测量
因此,您的RelativeLayout
的宽度应为0dp,其余的宽度相同。我猜这就是问题所在。当你练习举重时,总是根据方向给孩子们的身高或宽度0dp
,然后让体重来测量
因此,您的RelativeLayout
的宽度应为0dp,其余的宽度相同。我猜这就是问题所在。问题在于,您也在dp中设置宽度,这会使重量增加,请尝试将其设置为0dp
问题是,在dp中设置的宽度会使重量增加,请尝试将其设置为0dp
您是否尝试过使用android:maxLength=“…”
来限制省略号时的文本长度?是的,这就像maxWidth,如果您不想让屏幕适应用户设备,我不确定这是否是一个好的解决方案(也许您想在大屏幕上显示10个字母,在小屏幕上仅显示4或5个字母)?这不是理想的解决方案。正确的处理方法是按照公认的答案指定适当的重量和宽度0dp。如果您使用的是android:maxLength,我建议您为每分钟屏幕宽度动态定义字符数,单位为dimens。您是否尝试过在省略时使用android:maxLength=“…”
来限制文本长度?是的,它类似于maxWidth,如果您不想使屏幕适应用户设备,我不确定这是一个好的解决方案(也许你想在大屏幕上显示10个字母,在小屏幕上只显示4或5个字母)?这不是理想的解决方案。正确的处理方法是按照公认的答案指定适当的重量和宽度0dp。但是,如果您使用android:maxLength,我建议为每个最小屏幕宽度动态定义以十分之一为单位的字符数。您的答案对我的情况也很完美,我只是接受了Uday答案,因为它可以类似案例中的lp人员(没有我的代码)您的答案对我的案例也很完美,我刚刚接受了Uday答案,因为它可以帮助类似案例中的人员(没有我的代码)谢谢你的回答!如果你想让你的界面适应不同大小的设备,你不认为这可能是个问题吗?@gamerounet这应该不是个问题。但不是重量,(这已经过时了)你可以试试PercentageRelativeLayout谢谢你的回答!如果你想让你的界面适应不同大小的设备,你不认为这可能是个问题吗?@gamerounet这应该不是个问题。但是你可以试试PercentageRelativeLayout,而不是权重(已经过时了)