//新建一个BlankFragment
BlankFragment blankFragment = new BlankFragment();
//布局替换成Fragment
getSupportFragmentManager().beginTransaction().add(R.id.imageView,blankFragment).commit();
//滑动布局
<!--主题滑动部分-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginTop="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout">
<androidx.core.widget.NestedScrollView
android:layout_width="407dp"
android:layout_height="727dp"
android:fillViewport="true"
android:contentDescription="主体部分类"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
//加载网络图片
ImageView imageView = findViewById(R.id.imageView4);
String url = "http://t13.baidu.com/it/u=123351041,2873697704&fm=224&app=112&f=JPEG?w=500&h=500.jpg";
//加载图片 添加网络权限
Glide.with(this)
.load(url)
.apply(RequestOptions.bitmapTransform(new RoundedCorners(100)))
.into(imageView);
//整体上移,包括状态栏
ImmersionBar.with(this).init();
//轮播图
List<String> list = new ArrayList<>();
list.add("https://img2.baidu.com/it/u=671627531,2759942804&fm=253&fmt=auto&app=138&f=JPEG?w=900&h=500.jpg");
list.add("https://img1.baidu.com/it/u=4158579023,1583009125&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=504.jpg");
Banner banner = findViewById(R.id.banner);
banner.setAdapter(new BannerImageAdapter<String>(list) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
//打开网络权限
Glide.with(holder.itemView)
.load(data)
.into(holder.imageView);
}
});
//先在布局文件中手动加入Banner
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginStart="30dp"
android:layout_marginTop="180dp"
android:layout_marginEnd="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
//给轮播图添加指示点
banner.setIndicator(new CircleIndicator(this));
banner.setIndicatorRadius(100);
//Fragment中点击事件
View view = inflater.inflate(R.layout.first_fragment1, container, false);
ImageView imageView = view.findViewById(R.id.imageView10);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
// Inflate the layout for this fragment
return view;
课设常用代码
最新推荐文章于 2024-10-17 11:31:44 发布