android gridlayout 列宽超过父(gridlayout)宽度
android gridlayout column width exceed parent (gridlayout) width
我正在使用 gridlayout
对我的观点进行分组。在里面,我有两列。一列有一个子项是 relativelayout
,另一列有一个子项是 linearlayout
.
我的 linearlayout
方向是 vertical
。它有两个视图,文本视图和图像视图。
问题是当我在 textview
中键入文本时,文本很长 ,我看不到
textview
中的一些字符
imageview
低于 textview
textview
宽度正在扩展并且 并在进入第二行之前隐藏其中的一些字符和图像视图(textview 是 muitiline)
我不想使用边距来解决这个问题,因为如果我使用它,textview
中的文本很短,不需要space会出现在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
和 imageview?.
为了解决这个问题,我使用 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>
我正在使用 gridlayout
对我的观点进行分组。在里面,我有两列。一列有一个子项是 relativelayout
,另一列有一个子项是 linearlayout
.
我的 linearlayout
方向是 vertical
。它有两个视图,文本视图和图像视图。
问题是当我在 textview
中键入文本时,文本很长 ,我看不到
textview
中的一些字符
imageview
低于textview
textview
宽度正在扩展并且 并在进入第二行之前隐藏其中的一些字符和图像视图(textview 是 muitiline)
我不想使用边距来解决这个问题,因为如果我使用它,textview
中的文本很短,不需要space会出现在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
和 imageview?.
为了解决这个问题,我使用 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>