fragment:译为碎片,旨在完成小手机和大手机之间的空白间隙(例如手机和平板),可以根据他们的尺寸,动态的显示UI界面。
使用步骤:
<fragment>(.xml,name定位到继承Fragment的类)
-> .class extent Fragment(重写onCreateView,inflate.inflate(R到展示数据的视图))
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<fragment
android:id="@+id/left_fragment"
android:name="com.lidantao.newsapp.fragments.NewsRightFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
public class NewsRightFragment extends Fragment {
private View view;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.content, container, false);
return view;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/news_title_txt"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="100dp"
android:textColor="@color/material_dynamic_neutral70"
android:textSize="@android:dimen/app_icon_size"
/>
</LinearLayout>
持续更新…