【问题标题】:android gridlayout column width exceed parent (gridlayout) widthandroid gridlayout列宽超过父(gridlayout)宽度
【发布时间】:2016-10-14 23:27:10
【问题描述】:

我正在使用gridlayout 对我的观点进行分组。在里面,我有两列。一列有一个子级relativelayout,另一列有一个子级linearlayout

我的linearlayout 方向是vertical。它有两个视图,textview 和一个 imageview。

问题是当我在textview 中输入文字时,文字很长,我看不到

  • textview 中的一些字符
  • imageview 低于 textview

textview 宽度正在扩展,在进入第二行之前隐藏其中的一些字符和 imageview(textview 是 muitiline)

我不想使用margin来解决这个问题,因为如果我使用它,并且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 一切正常。但是如果我从150 输入,我看不到一些数字,比如从3032 和imageview?。

【问题讨论】:

  • 您到底想要什么结果?您希望您的文本转到另一行,还是将文本从末尾的 put ... 符号中删除?
  • @Aksiom 我的文本视图位于垂直线性布局内。在这个布局中,我希望包括 textview 在内的每个视图都在右侧对齐。所以当textview宽度增加时,下面的一些view就看不到了
  • @Aksiom 请查看我编辑的问题。
  • 你解决了吗?
  • @vojta 请看下面的答案

标签: android android-layout android-view textview android-gridlayout


【解决方案1】:

为了解决这个问题,我使用RelativeLayout 代替LinearLayout 并将我的textviewimageview 的开头对齐

<?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>

【讨论】:

    猜你喜欢
    • 2014-04-20
    • 1970-01-01
    • 2016-03-09
    • 2013-12-08
    • 2023-02-14
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多