【发布时间】:2015-10-18 14:55:57
【问题描述】:
这是我的 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Mucitler"
android:textColor="#000"
android:textSize="16sp"/>
</android.support.v7.widget.Toolbar>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
这是我的 custom_recycler_view_row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card:cardBackgroundColor="#ffffff"
card:cardCornerRadius="5dp"
card:cardElevation="2dp"
card:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/imageFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivImageOfCity"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/android_image"/>
<TextView
android:id="@+id/tvNameOfCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#55000000"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:singleLine="true"
android:text="Sehir Adı"
android:textColor="#fff"
android:textSize="18sp"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageFrame"
android:orientation="vertical">
<TextView
android:id="@+id/tvCountryOfCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Austalia"/>
<TextView
android:id="@+id/tvPopulationOfCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="1 M population"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
如何在带有片段的活动中显示 RecyclerView 和 CardView 布局?我也有 MainActivity 和 City Model 代码。请帮助我,谢谢。
【问题讨论】:
-
我不明白你想要做什么。但是,看着它,我认为您想使用
CardView,因为它作为您的RecycleView上的物品的持有者具有高度,对吗? -
我有两个布局,分别是自定义 recyclerview 和 main,我正在将数据从 City 类导入到 RecyclerView 对象。此外,我正在使用 NavigationDrawer,当我单击 NavDrawer 上的城市部分时,我想将 City Fragment 带到 Acitivy。得到它?更多请查看:github.com/Viveka/AndroidEgitimi/tree/master/…
标签: android android-fragments android-activity android-recyclerview android-fragmentactivity