用于记录安卓开发功能
效果图:
实现步骤:
1.引入banner依赖
implementation 'com.youth.banner:banner:1.4.9'
implementation 'com.squareup.picasso:picasso:2.5.2'
或者
com.youth.banner:banner:1.4.9
com.squareup.picasso:picasso:2.5.2
2.在XML加入Banner组件
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="200dp" />
3.在Fragment页面上设置banner
package com.example.wechatapplication.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.wechatapplication.R;
import com.example.wechatapplication.utils.Picss;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import java.util.ArrayList;
import java.util.List;
public class HomeFragment extends Fragment {
public View view;
private List<String> images;
private List<Integer> img;
private List<String> titles;
private Banner banner;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false);
initDate();
initBanner();
// return inflater.inflate(R.layout.fragment_home, container, false);
return view;
}
private void initDate() {
// images = new