Android 文本不适合线性布局中的屏幕
以下布局中使用的文本视图不会被包装在屏幕中,而是在屏幕的左(或开始)边缘显示Android 文本不适合线性布局中的屏幕,android,textview,android-linearlayout,Android,Textview,Android Linearlayout,以下布局中使用的文本视图不会被包装在屏幕中,而是在屏幕的左(或开始)边缘显示 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/text_pane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/iv_video_thumbnail"
android:layout_toStartOf="@+id/iv_video_thumbnail"
android:orientation="vertical">
<TextView
android:id="@+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="end"
android:padding="@dimen/text_padding"/>
<TextView
android:padding="@dimen/text_padding"
android:layout_gravity="end"
android:id="@+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<ImageView
android:id="@+id/iv_video_thumbnail"
android:layout_width="@dimen/thumbnail_width"
android:layout_height="@dimen/thumbnail_height"
android:layout_alignBottom="@+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:contentDescription="@string/video_thumbnail_image"
app:srcCompat="@drawable/video" />
</RelativeLayout>
我不知道为什么左边的文字会从屏幕上消失。我曾尝试对相对布局
和线性布局
以及两个文本视图
使用边距和填充,但都没有解决问题。目前,该应用程序显示的内容如下:
正如您在代码中看到的,我还将
gravity
属性应用于TextView,但尚未成功。有人知道如何解决这个问题吗?试试这个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/text_pane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/iv_video_thumbnail"
android:layout_toStartOf="@+id/iv_video_thumbnail"
android:layout_weight=".2"
android:orientation="vertical">
<TextView
android:id="@+id/tv_video_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="right"
android:layout_margin="3dp"
android:layout_weight=".1"
android:padding="10dp"/>
<TextView
android:padding="10dp"
android:id="@+id/tv_video_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight=".3"
android:text="" />
</LinearLayout>
<ImageView
android:id="@+id/iv_video_thumbnail"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_weight=".1"
android:scaleType="fitXY"
android:layout_alignParentRight="true"/>
</LinearLayout>
输出:
试试这个
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:padding="10dp"
android:text="@android:string/dialog_alert_title"
app:layout_constraintEnd_toStartOf="@+id/iv_video_thumbnail"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:padding="10dp"
android:text="@android:string/fingerprint_icon_content_description"
app:layout_constraintEnd_toStartOf="@+id/iv_video_thumbnail"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_video_title" />
<ImageView
android:id="@+id/iv_video_thumbnail"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/tv_video_descr"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/your_img" />
</android.support.constraint.ConstraintLayout>
改用此布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/text_pane"
android:layout_width="0dp"
android:padding="@dimen/text_padding"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:orientation="vertical">
<TextView
android:id="@+id/tv_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Hi" />
<TextView
android:id="@+id/tv_video_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Hi" />
</LinearLayout>
<ImageView
android:id="@+id/iv_video_thumbnail"
android:layout_width="0dp"
android:layout_height="@dimen/thumbnail_height"
android:layout_alignBottom="@+id/text_pane"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_weight="0.3"
app:srcCompat="@drawable/video" />
</LinearLayout>
非常复杂的问题,您能告诉我们您在线性布局中设置文本是什么意思吗?您有3个文本视图
,所有这些视图都可以作为属性集正常工作。确保您知道LinearLayout
是如何工作的。您是否尝试为包含两个文本视图的LinearLayout设置一些填充?(大约10dp)。@jasonStack请使用约束布局它是更好的布局抱歉@Jibèaᴎ喀ᴎ 因为听起来很复杂。文本开始部分被剪裁,整个文本不符合列表项。@KiranBennyJoseph我想我不能使用ConstraintLayout,因为这是一个ListView项,它反过来嵌套在ConstraintLayout中。它正在工作。请仔细检查。我将更新图像的外观使用Imageviewandroid:scaleType=“fitXY”中的这一行