【发布时间】:2016-09-23 10:27:09
【问题描述】:
从服务器读取数据并在卡片视图中显示。我做了很多方法来赋予卡片视图权重但不起作用!
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:layout_gravity="center"
android:id="@+id/img"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_name"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_api_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
看起来像这样:
但希望我的卡片视图看起来像这样:
我该怎么做?重要的是:不想给出像 50dp 这样的高度数 想要给重量,因为想要在所有设备中看起来像 pic2 。请帮助tnx
【问题讨论】:
-
权重适用于线性布局,而不是卡片视图
-
知道!但我总是把我的元素放在衬里布局中,然后用它来增加重量。如果你有一些解决方案给我不要教我
标签: android xml android-layout android-studio android-cardview