fragment布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
android:id="@+id/hoem_news_ptsv"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_gravity="center"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/home_news_img"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
<TextView
android:id="@+id/home_news_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="2" />
</LinearLayout>
</android.support.v7.widget.CardView>
<application.com.ayy.lenovo.zy0502.ui.MyList
android:id="@+id/hoem_news_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"></application.com.ayy.lenovo.zy0502.ui.MyList>
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</LinearLayout>
news_activity
public class NewsActivity extends BaseActivity {
private DrawerLayout news_drawer;
private RadioGroup news_radio;
private NavigationView news_nav;
@Override
public void initView() {
news_radio = findViewById(R.id.news_radio);
news_nav = findViewById(R.id.news_nav);
news_drawer = findViewById(R.id.news_drawer);
}
@Override
public void setView() {
setFragment(new Fragment_Home());
}
@Override
public int getLayout() {
return R.layout.activity_news;
}
@Override
public void setLinstener() {
news_radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio1:
setFragment(new Fragment_Home());
break;
case R.id.radio2:
setFragment(new Fragment_Find());
break;
case R.id.radio3:
setFragment(new Fragment_Self());
break;
}
}
});
news_nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_item1:
Toast.makeText(NewsActivity.this, "nav_item1", Toast.LENGTH_SHORT).show();
news_drawer.closeDrawers();
break;
case R.id.nav_item2:
Toast.makeText(NewsActivity.this, "nav_item2", Toast.LENGTH_SHORT).show();
news_drawer.closeDrawers();
break;
case R.id.nav_item3:
Toast.makeText(NewsActivity.this, "nav_item3", Toast.LENGTH_SHORT).show();
news_drawer.closeDrawers();
break;
case R.id.nav_item4:
Toast.makeText(NewsActivity.this, "nav_item4", Toast.LENGTH_SHORT).show();
news_drawer.closeDrawers();
break;
case R.id.nav_item5:
Toast.makeText(NewsActivity.this, "nav_item5", Toast.LENGTH_SHORT).show();
news_drawer.closeDrawers();
break;
}
return false;
}
});
}
private void setFragment(Fragment fragment) {
getSupportFragmentManager().beginTransaction().replace(R.id.news_frame, fragment).commit();
}
}