【问题标题】:Textview hides long text and view as wellTextview 也隐藏了长文本和视图
【发布时间】:2016-07-12 16:33:42
【问题描述】:
  • 我为操作栏创建了布局,其中我使用了权重为 1 的线性布局,其中包含标题的 Textview 和图标的 Imageview。
  • 但是当标题中设置了长文本时,它也会隐藏文本和部分图标。
  • 您可以在图片中看到。
  • 我只需要在此处显示文字的图标,因为我不在 textview 中使用 weight=1。

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:background="@color/actionbar_color"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="?android:attr/actionBarSize"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/imgActionLeftIcon"
        android:layout_width="?android:attr/actionBarSize"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/action_btn_margine"
        android:src="@drawable/menu_logo" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/txtActionTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:maxLines="1"
            android:ellipsize="end"
            android:text="Medium Text ghjhjgjkghdfggh"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF"
            android:textStyle="bold" />
        <ImageView
            android:layout_width="@dimen/action_btn_height_width"
            android:layout_height="match_parent"
            android:padding="@dimen/_2sdp"
            android:src="@mipmap/ic_launcher" />
    </LinearLayout>
    <ImageView
        android:id="@+id/imgActionRightIcon"
        android:layout_width="?android:attr/actionBarSize"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/action_btn_margine"
        android:src="@drawable/menu_logo" />
</LinearLayout>

输出

【问题讨论】:

    标签: android xml textview


    【解决方案1】:

    解决了这个问题。查看我的代码(添加属性layout_weight):

    <TextView
                android:id="@+id/txtActionTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"
                android:gravity="center"
                android:maxLines="1"
                android:ellipsize="end"
                android:text="Medium Text ghjhjgjkghdfggh"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#FFFFFF"
                android:textStyle="bold" />
    

    【讨论】:

    • 感谢您的回答,但我还在上面定义了我已经使用过 android:layout_weight="1" 它可以工作,但问题是如果 textview 文本很小,那么图标最后也会放在标题和图标。这就是我没有使用 android:layout_weight="1" 的原因。
    • @Sam。您能否发布一张您需要实现的目标的图片?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2013-12-31
    相关资源
    最近更新 更多