android - 如果 textview 中的文本很大 Android,Textview 会超越 ImageView 吗?

标签 android android-layout

我创建了自定义操作栏,其左侧有后退按钮的 ImageView,中间有标题 TextView 。我希望标题居中。但是,如果文本很大,它会占据所有可用宽度并与 Imageview 重叠,因此 ImageView 监听器不起作用,只有单击时的 TextView 可以在自定义布局上的任何位置工作。以下是截图,向您解释更多。

TextView if large overlaps Back ImageView and onClick of Image doesnt work

如果 Textview 很大,我希望 textView 居中并将所有字符向右移动以获得可用宽度,然后以...结尾

以下是我的XML代码:

<RelativeLayout
            android:id="@+id/actionbar"
            android:layout_width="match_parent"
            android:layout_height="45dip"
            android:layout_alignParentTop="true"
            android:alpha="0.8"
            android:background="@android:color/black"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/backbutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:paddingLeft="10dp"
                android:src="@drawable/back" />

            <TextView
                android:id="@+id/titleofscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:maxLines="1"
                android:textColor="#22c064"
                android:textSize="18sp" />
        </RelativeLayout>

请帮助我想要像 TextView center 这样的东西,它应该看起来像 asdasdasdasd ...

最佳答案

check this使用只需要提供权重,以便每个 View 获得总宽度的百分比。

    <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="45dip"
android:alpha="0.8"
android:background="@android:color/black"
android:orientation="horizontal"
android:weightSum="2" >

<ImageView
    android:id="@+id/backbutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.25"
    android:paddingLeft="10dp"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/titleofscreen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1.75"
    android:maxLines="1"
    android:layout_gravity="center"
    android:paddingLeft="5dp"
     android:text="[2014-10-20 17:05:35 - NVOLV3] Unknown error: java.lang.NullPointerException [2014-10-20 17:05:35 - NVOLV3] Unknown error: java.lang.NullPointerException"
    android:singleLine="true"
    android:textColor="#22c064"
    android:textSize="18sp" />

  </LinearLayout>

关于android - 如果 textview 中的文本很大 Android,Textview 会超越 ImageView 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464918/

相关文章:

c# - 在 "Add Payment Method"屏幕上启动 Google Pay

java.lang.IllegalStateException : Could not execute method of the activity, 如何解决?

android - 在不截断文本的情况下旋转 TextView

java - Android如何绘制像这样的线性布局角形状

android - 渐变背景在某些设备上不起作用

android - 动态创建自定义 ListView 问题

java - 如何删除 Android 开发的 Eclipse/bin/dexedLibs 文件夹中出现的重复库?

android - 如何将数据从android发送到用java制作的google app engine web应用程序

android - 为什么图像是重复的( picasso )

java - TextView 在应用程序中不可点击