我正在使用 gridlayout
对我的 View 进行分组。在里面,我有两列。一列有一个子项 relativelayout
,另一列有一个子项 linearlayout
。
我的linearlayout
方向是垂直
。它有两个 View ,textview 和 imageview。
问题是当我在 textview
中键入文本时,文本很长,我看不到
textview
中的一些字符>imageview
位于textview
下方
textview
宽度正在扩展并且并在进入第 2 行之前隐藏它的一些字符和 imageview(textview 是多行的)
我不想使用边距来解决这个问题,因为如果我使用它,并且 textview
中的文本很短,不需要的空间会出现在右边 TextView 的一侧。
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2"
app:rowCount="1" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill" >
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12345...50" >
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/vladmir putin"/>
</LinearLayout>
</android.support.v7.widget.GridLayout>
如何解决textview宽度超过gridlayout宽度的问题?
如果我输入 1234
一切正常。但是如果我输入从 1
到 50
,我看不到一些数字,比如从 30
到 32
和图片 View ?
最佳答案
为了解决这个问题,我使用了RelativeLayout
而不是 LinearLayout
并对齐我的 textview
到 imageview
的开头
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2"
app:rowCount="1"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill" >
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/profile"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="12345...50"
android:layout_toStartOf="@id/profile">
</TextView>
<ImageView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:src="@drawable/profile"
android:id="@+id/profile"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
关于android gridlayout 列宽超过父(gridlayout)宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37808475/