效果如下
轮播图的开源项目地址
https://github.com/youth5201314/banner/blob/master/README.md
具体布局为
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--轮播图片-->
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.Toolbar
android:id="@+id/grad_toolbar"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--主体内容-->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
app:cardCornerRadius="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/userText"
android:text="dadasdasdasdasdsdasdadsdasdasddasdasasd
adsdasdasdasasdasdasdasddsadaddadasdasdasddsdads
sdsdasdasdasdadsdasdasdasdasdasdasdasdasdasdasdasdsdasdsdadsd"
android:textAppearance="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small" />
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:id="@+id/grade_Text"
android:text="评分"
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Title" />
<RatingBar
android:id="@+id/rbRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:id="@+id/grade_Text1"
android:text="评分为"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<Button
android:id="@+id/submission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@drawable/shape"
android:text="提 交"
android:textColor="#ffffff"
android:textSize="18dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
活动里面的图片设置,轮播图的更多详细用法请移步上面的开源项目
Banner banner = (Banner) findViewById(R.id.banner);
List images=new ArrayList<>();
images.add(R.drawable.user1);
images.add(R.drawable.user);
banner.setImages(images).setImageLoader(new GlideImageLoader()).start();
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load(path).into(imageView);
}
}