xml代码
<?xml version="1.0" encoding="utf-8"?>
<phonestock.exch.ui.ResizeTabHost
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical"
style="@style/xct_lthj_layout_width_height_ff">
<LinearLayout android:orientation="horizontal" android:background="@drawable/xct_lthj_topback"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:id="@id/xct_lthj_refresh" android:layout_gravity="center_vertical"
android:textSize="@dimen/xct_lthj_fontSize_eighteen" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/xct_lthj_refresh" android:adjustViewBounds="true"
android:scaleType="center"/>
<RadioGroup android:layout_marginLeft="@dimen/xct_lthj_space_ten" android:layout_marginRight="@dimen/xct_lthj_space_ten"
android:layout_gravity="center" android:orientation="horizontal" android:fitsSystemWindows="true"
android:id="@id/xct_lthj_main_radio" style="@style/xct_lthj_layout_width_height_wf">
<RadioButton android:id="@id/xct_lthj_radio_button0"
android:background="@drawable/xct_lthj_frmtopback"
android:gravity="center" android:layout_weight="1"
style="@style/xct_lthj_layout_width_height_ww" android:button="@null"
android:textColor="@color/xct_lthj_back"/>
<RadioButton android:id="@id/xct_lthj_radio_button1"
android:background="@drawable/xct_lthj_frmtopback"
android:gravity="center" android:layout_weight="1"
style="@style/xct_lthj_layout_width_height_ww" android:button="@null"
android:textColor="@color/xct_lthj_back"/>
<RadioButton android:id="@id/xct_lthj_radio_button2"
android:background="@drawable/xct_lthj_frmtopback"
android:gravity="center" android:layout_weight="1"
style="@style/xct_lthj_layout_width_height_ww" android:button="@null"
android:textColor="@color/xct_lthj_back"/>
</RadioGroup>
</LinearLayout>
<!-- android:layout_weight="1" -->
<TabWidget android:id="@android:id/tabs" android:visibility="gone"
android:layout_weight="0.0" style="@style/xct_lthj_layout_width_height_wf" />
<TextView android:layout_height="@dimen/xct_lthj_space_twozeroone" android:layout_width="fill_parent"
android:background="@color/xct_lthj_historyback" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="@dimen/xct_lthj_space_zero"
android:layout_weight="1.0" />
</LinearLayout>
</phonestock.exch.ui.ResizeTabHost>
ResizeTabHost的代码
package phonestock.util;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TabHost;
public class ResizeTabHost extends TabHost{
private OnResizeListener mListener;
public interface OnResizeListener {
void OnResize(int w, int h, int oldw, int oldh);
}
public void setOnResizeListener(OnResizeListener l) {
mListener = l;
}
public ResizeTabHost(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mListener != null) {
mListener.OnResize(w, h, oldw, oldh);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
具体的使用
/**
* 初始化底部按钮
*/
private void initRadios() {
RadioButton button0 = ((RadioButton) findViewById(Lthjlink
.getIdxct_lthj_radio_button0()));
button0.setText(Lthjlink.getStringxct_lthj_tab_buy());
button0.setOnCheckedChangeListener(new myonCheckedChanged());
RadioButton button1 = ((RadioButton) findViewById(Lthjlink
.getIdxct_lthj_radio_button1()));
button1.setText(Lthjlink.getStringxct_lthj_tab_sell());
button1.setOnCheckedChangeListener(new myonCheckedChanged());
RadioButton button2 = ((RadioButton) findViewById(Lthjlink
.getIdxct_lthj_radio_button2()));
button2.setText(Lthjlink.getStringxct_lthj_tab_entrust());
button2.setOnCheckedChangeListener(new myonCheckedChanged());
}
private void setupIntent() {
tabHost = getTabHost();
LayoutInflater.from(this).inflate(
Lthjlink.getLayoutxct_lthj_newtradebuy_portrait(),
tabHost.getTabContentView(), true);
// mHost.setBackgroundResource(R.drawable.upomp_lthj_bg_main);
tabHost.addTab(buildTabSpec("buytag",
Lthjlink.getStringxct_lthj_tab_buy(),
Lthjlink.getDrawablexct_lthj_frmtopback(),
Lthjlink.getIdxct_lthj_tab1()));
tabHost.addTab(buildTabSpec("selltag",
Lthjlink.getStringxct_lthj_tab_sell(),
Lthjlink.getDrawablexct_lthj_frmtopback(), this.sellActivity));
tabHost.addTab(buildTabSpec("chedantag",
Lthjlink.getStringxct_lthj_tab_entrust(),
Lthjlink.getDrawablexct_lthj_frmtopback(), this.entrustActivity));
}
private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
final Intent content) {
return tabHost
.newTabSpec(tag)
.setIndicator(getString(resLabel),
getResources().getDrawable(resIcon))
.setContent(content);
}
private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
final int content) {
return tabHost
.newTabSpec(tag)
.setIndicator(getString(resLabel),
getResources().getDrawable(resIcon))
.setContent(content);
}
/**
* 切换模块
*/
public class myonCheckedChanged implements
android.widget.CompoundButton.OnCheckedChangeListener {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
//模块切换,
}
}
}