【发布时间】:2017-11-11 21:06:52
【问题描述】:
解决方案将 layout_weight="1" 添加到文本视图中有许多类似的问题。我试过了,但它没有帮助我。我的情况不同。不要认为它是重复的。
下面是我想做的布局。如果图像视图中有图像,则 TextView 应该换行。如果没有图像,应该是原样。
下面是我目前尝试的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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:layout_margin="5dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_alignParentStart="true"
android:gravity="start|center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here which should wrap depending upon
the string length and also considering whether or not there is an image adjacent to it"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text here"/>
</LinearLayout>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:adjustViewBounds="true"
android:src="@drawable/save"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
下面是这段代码的结果。 TextView 在 ImageView 下不换行。
我的方法错了吗?有人可以帮我解决这个问题。我正在使用最低 api 级别 21 开发的 AndroidStudio 3.0(如果这很重要)。 提前致谢
【问题讨论】:
标签: android android-layout android-linearlayout android-cardview