gpt4 book ai didi

Android:当 LinearLayout 中没有可用空间时自动截断文本

转载 作者:行者123 更新时间:2023-11-29 14:55:15 25 4
gpt4 key购买 nike

我想在我的应用程序中创建某种工具栏。在左边我显示一个固定大小的 imageView,在右边另一个我想显示一个文本,但它需要被截断以防没有足够的空间......这就是我的地方'失败

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="32dp"
android:background="@android:drawable/title_bar"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="left|center_vertical"
android:orientation="horizontal" >

<ImageButton
android:id="@+id/actionBarIcon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="7dp"
android:adjustViewBounds="true"
android:background="@drawable/podcast_addict"
android:gravity="center_vertical"
android:onClick="onHome" >
</ImageButton>

<TextView
android:id="@+id/actionBarTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:singleLine="true"
android:text="@string/app_name"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="2"
android:gravity="right|center_vertical"
android:orientation="horizontal" >

<ImageView
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="3dp"
android:background="@android:drawable/status_bar_item_app_background" />

<ImageView
android:id="@+id/actionButton"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:adjustViewBounds="true"
android:background="@android:drawable/stat_notify_sync_noanim"
android:gravity="center_vertical"
android:onClick="onAction" >
</ImageView>

<ImageView
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:background="@android:drawable/status_bar_item_app_background" />

<ImageButton
android:id="@+id/showHideButton"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:adjustViewBounds="true"
android:background="@android:drawable/ic_menu_view"
android:gravity="center_vertical"
android:onClick="onShowHide" >
</ImageButton>

<ImageView
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:background="@android:drawable/status_bar_item_app_background" />

<ImageButton
android:id="@+id/markReadButton"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:adjustViewBounds="true"
android:background="@android:drawable/checkbox_on_background"
android:gravity="center_vertical"
android:onClick="onMarkRead" >
</ImageButton>
</LinearLayout>

</LinearLayout>

当文本很短时它似乎可以工作,但是当它太长时右侧的第一个 imageView 隐藏在文本后面......我该如何解决这个问题?

最佳答案

尝试使用 android:ellipsize :

<TextView
android:singleLine="true"
android:ellipsize="end"
android:text="This is a long long text"/>

当文本长于 TextView 宽度时,这将在屏幕上显示This is a long...

关于Android:当 LinearLayout 中没有可用空间时自动截断文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8348922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com