这是我的代码:
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentPaddingLeft="@dimen/activity_horizontal_margin"
app:cardUseCompatPadding="true"
app:cardElevation="4dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:layout_width="match_parent" android:src="@drawable/ic_open_in_new_black_48dp"
android:layout_height="match_parent"/>
<TextView android:text="in card view" android:layout_gravity="center_vertical"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v7.widget.CardView>
我希望第一行使用第一个ImageView和第二个TextView,但我得到:
如何解决?
答案 0 :(得分:1)
您正在使用match_parent
中的android:layout_width
和android:layout_height
进行imageview。
将其更改为wrap_content。
答案 1 :(得分:0)
使用RelativeLayout取代LinearLayout,将用户“alignParentLeft”用于ImageView
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentPaddingLeft="@dimen/activity_horizontal_margin"
app:cardUseCompatPadding="true"
app:cardElevation="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:src="@drawable/ic_open_in_new_black_48dp"
android:layout_height="match_parent"
android:alignParentLeft="true"
/>
<TextView
android:text="in card view"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v7.widget.CardView>