Android fragment应用

 

public class listfragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_1,container,false);
        return view;
    }
}
<fragment
    android:id="@+id/fragment"
    android:name="com.example.myapplicationtest.listfragment"
    android:layout_width="395dp"
    android:layout_height="445dp"
    android:layout_weight="1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/linearLayout"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="6dp"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/list">

    <ImageView
        android:id="@+id/image1"
        android:layout_width="10dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher_background" />
    <ImageView
        android:id="@+id/image2"
        android:layout_width="10dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher_background" />
    <ImageView
        android:id="@+id/image3"
        android:layout_width="10dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher_background" />
    <ImageView
        android:id="@+id/image4"
        android:layout_width="10dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher_background" />

</LinearLayout>

 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment1);
    ImageView imageView1=findViewById(R.id.image1);
    ImageView imageView2=findViewById(R.id.image2);
    ImageView imageView3=findViewById(R.id.image3);
    ImageView imageView4=findViewById(R.id.image4);
    imageView1.setOnClickListener(l);
    imageView2.setOnClickListener(l);
    imageView3.setOnClickListener(l);
    imageView4.setOnClickListener(l);
}
View.OnClickListener l=new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        FragmentManager fm=getSupportFragmentManager();
        FragmentTransaction ft=fm.beginTransaction();
        Fragment f=null;
        switch (v.getId())
        {
            case R.id.image1:
            f=new listfragment();
            break;
            case R.id.image2:
                f=new fragmen2();
                break;
            case R.id.image3:
                f=new fragment3();
                break;
            case R.id.image4:
                f=new fragment3();
                default:break;

        }
        ft.replace(R.id.fragment,f);
        ft.commit();
    }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值