fragment和radiobutton做出类tabhost效果
首先给两个截图看一下 基本框架,java和xml文件
成都创新互联是一家业务范围包括IDC托管业务,网络空间、主机租用、主机托管,四川、重庆、广东电信服务器租用,IDC机房托管,成都网通服务器托管,成都服务器租用,业务范围遍及中国大陆、港澳台以及欧美等多个国家及地区的互联网数据服务公司。
每一个java对应一个Fragment,每一个Fragment对应一个xml文件
主要内容:
如何定制RadioButton:
设置radiobutton的android:button="@null";
设置radiobutton的android:background为一个自定义selector
设置alignparentbottom=true;
废话不多说了,上
.-' _..`.
/ .'_.'.'
| .' (.)`.
;' ,_ `.
.--.__________.' ; `.;-'
| ./ /
| | /
`..'`-._ _____, ..'
/ | | | |\ \
/ /| | | | \ \
/ / | | | | \ \
/_/ |_| |_| \_\
|__\ |__\ |__\ |__\
ZhuActivity java代码
package net.xiaocool.yunzhu.activity;
/**
* Created by Administrator on 2015/6/11.
*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import net.xiaocool.yunzhu.R;
public class ZhuActivity extends FragmentActivity {
private Fragment[] mFragments;
private RadioGroup bottomRg;
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private RadioButton rbone, rbTwo, three, rbFour;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.textradiobutton);
mFragments = new Fragment[4];
fragmentManager = getSupportFragmentManager();
mFragments[0] = fragmentManager.findFragmentById(R.id.fragement_dingdan);
mFragments[1] = fragmentManager.findFragmentById(R.id.fragement_dingdan);
mFragments[2] = fragmentManager.findFragmentById(R.id.fragement_chat);
mFragments[3] = fragmentManager.findFragmentById(R.id.fragement_chaper);
fragmentTransaction = fragmentManager.beginTransaction()
.hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3]);
fragmentTransaction.show(mFragments[0]).commit();
setFragmentIndicator();
}
private void setFragmentIndicator() {
bottomRg = (RadioGroup) findViewById(R.id.group);
rbone = (RadioButton) findViewById(R.id.one);
rbTwo = (RadioButton) findViewById(R.id.two);
three = (RadioButton) findViewById(R.id.three);
rbFour = (RadioButton) findViewById(R.id.four);
bottomRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
fragmentTransaction = fragmentManager.beginTransaction()
.hide(mFragments[0]).hide(mFragments[1])
.hide(mFragments[2]
).hide(mFragments[3]);
switch (checkedId) {
case R.id.one:
fragmentTransaction.show(mFragments[0]).commit();
break;
case R.id.two:
fragmentTransaction.show(mFragments[1]).commit();
break;
case R.id.three:
fragmentTransaction.show(mFragments[2]).commit();
break;
case R.id.four:
fragmentTransaction.show(mFragments[3]).commit();
break;
default:
break;
}
}
});
}
}
对应的xml文件
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
android:name="net.xiaocool.yunzhu.activity.Frag"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10" />
android:name="net.xiaocool.yunzhu.activity.Frag2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10" />
android:id="@+id/fragement_chat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10" />
android:name="net.xiaocool.yunzhu.activity.Frag4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
android:layout_width="96dp"
android:layout_height="wrap_content"
android:drawableTop="@drawable/change"
android:background="@drawable/bg_button_down"
android:button="@null"
android:padding="10dip"
android:text="Wechat"
android:textSize="20sp" />
android:layout_width="96dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_button_down"
android:button="@null"
android:padding="10dip"
android:text="Content"
android:textSize="20sp" />
android:layout_width="96dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_button_down"
android:button="@null"
android:padding="10dip"
android:text="Find"
android:textSize="20sp"
/>
android:layout_width="96dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_button_down"
android:button="@null"
android:padding="10dip"
android:text="Me"
android:textSize="20sp" />
四个Frag
package net.xiaocool.yunzhu.activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.xiaocool.yunzhu.R;
/**
* Created by Administrator on 2015/6/11.
*/
public class Frag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.frag1, container, false);
}
}
对应的xml文件
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#0061BB"
>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#EAF2FA"
android:text="订单"
android:textSize="30sp"
/>
android:layout_height="fill_parent"
android:gravity="center"
android:text="这是订单"
android:textColor="#000000" />
当前题目:fragment和radiobutton做出类tabhost效果
本文URL:http://scyanting.com/article/gjecds.html