Radiogroup+DrawerLayout切换效果
来源:互联网 发布:网络教育笔试考试 编辑:程序博客网 时间:2024/06/05 05:50
布局文件
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout android:id="@+id/dl" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.a.moni.MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/fl" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/rg" ></FrameLayout> <RadioGroup android:id="@+id/rg" android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="60dp"> <RadioButton android:id="@+id/rb1" android:layout_width="0dp" android:layout_height="60dp" android:textSize="16sp" android:layout_weight="1" android:background="@drawable/b1" android:button="@null" android:checked="true" android:gravity="center" android:padding="10dp" android:text="首頁" /> <RadioButton android:id="@+id/rb2" android:layout_width="0dp" android:layout_height="60dp" android:textSize="16sp" android:layout_weight="1" android:background="@drawable/b1" android:button="@null" android:gravity="center" android:padding="10dp" android:text="发现" /> <RadioButton android:id="@+id/rb3" android:layout_width="0dp" android:layout_height="60dp" android:textSize="16sp" android:layout_weight="1" android:background="@drawable/b1" android:button="@null" android:gravity="center" android:padding="10dp" android:text="下载" /> <RadioButton android:id="@+id/rb4" android:layout_width="0dp" android:layout_height="60dp" android:textSize="16sp" android:layout_weight="1" android:background="@drawable/b1" android:button="@null" android:padding="10dp" android:text="我的" /> </RadioGroup></RelativeLayout> <RelativeLayout android:id="@+id/rl" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#ffffff"> <ImageView android:id="@+id/image_touxiang" android:layout_width="match_parent" android:layout_height="100dp" android:layout_centerHorizontal="true" android:layout_margin="10dp" android:src="@mipmap/ic_launcher" /> <ListView android:id="@+id/list_view_drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/image_touxiang"> </ListView> </RelativeLayout></android.support.v4.widget.DrawerLayout>
activity
import android.os.Bundle;import android.support.annotation.IdRes;import android.support.v4.widget.DrawerLayout;import android.support.v7.app.AppCompatActivity;import android.widget.ArrayAdapter;import android.widget.FrameLayout;import android.widget.ListView;import android.widget.RadioGroup;import android.widget.RelativeLayout;import com.example.a.moni.fragment.Faxian;import com.example.a.moni.fragment.Shouye;import com.example.a.moni.fragment.Wode;import com.example.a.moni.fragment.Xiazai;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity { private FrameLayout fl; private RadioGroup rg; private DrawerLayout dl; private RelativeLayout rl; private ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); fl = (FrameLayout) findViewById(R.id.fl); dl = (DrawerLayout) findViewById(R.id.dl); rl = (RelativeLayout) findViewById(R.id.rl); lv = (ListView) findViewById(R.id.list_view_drawer); List<String> list=new ArrayList<>(); list .add("钱包"); list .add("行程记录"); list .add("好友邀请"); list .add("设置"); list .add("购买特权卡"); ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,android.R.id.text1,list); lv.setAdapter(adapter); rg=(RadioGroup)findViewById(R.id.rg); getSupportFragmentManager().beginTransaction().replace(R.id.fl, new Shouye()).commit(); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) { switch (i) { case R.id.rb1: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new Shouye()).commit(); break; case R.id.rb2: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new Faxian()).commit(); break; case R.id.rb3: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new Xiazai()).commit(); break; case R.id.rb4: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new Wode()).commit(); break; default: break; } } }); }}
阅读全文
0 0
- Radiogroup+DrawerLayout切换效果
- ViewPager和RadioGroup实现页面切换效果
- Android自定RadioGroup实现点击切换效果
- RadioGroup内部radioButton切换
- 点击RadioGroup切换Fragment
- RadioGroup+RadioButton切换Fragment
- 点击RadioGroup切换图片
- RadioGroup 点击切换背景图片
- Android DrawerLayout抽屉效果
- Android DrawerLayout抽屉效果
- DrawerLayout 抽屉效果
- DrawerLayout 抽屉效果 侧滑
- Android DrawerLayout抽屉效果
- DrawerLayout实现抽屉效果
- 自定义控件---继承ViewGroup类方式(循序渐进之第3步效果----图片左右拖动+RadioGroup切换效果)
- RadioGroup+Fragment实现Tab切换
- RadioGroup+Fragment实现界面切换
- RadioGroup+ViewPager组合切换监听
- Swift中 String、Array、Set、Dictionary的遍历方法
- NOIP2013TGDay1
- 【Node.js系列】Express 介绍
- DevExpress实现GridControl单元格编辑验证的方法
- EMwI插件更新:防XSS攻击
- Radiogroup+DrawerLayout切换效果
- 并行计算奇异值分解--Jacobi旋转(转)
- Viewpager+选项卡
- 51nod 1615 跳跃的杰克
- eclipse添加服务器时没有server选项怎么办
- C# WindowsForm程序同时启动多个窗口类
- spatiallite空间数据库转换到leaflet.js的GeoJson格式
- 怎么做共享充电宝方案
- 【第1088期】webpack & HTTP/2