我想隐藏屏幕点击上的标签并让它们重新出现在另一个屏幕点击上。我已经在很多应用程序中看到了这一点,所以这应该是可能的。我可以使用setvisibility = VIEW.GONE
. 我试过这个:
private OnClickListener tabClickListener = new OnClickListener() {
public void onClick(View v) {
if(v.getVisibility() == View.VISIBLE) {
v.setVisibility( View.GONE );
}
else if(v.getVisibility() == View.GONE){
v.setVisibility( View.VISIBLE );
}
}
};
这是xml代码:
enter code here
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
<TextView
android:id="@+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a fourth tab" />
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-5dp"/>
</LinearLayout>
</TabHost>
这是java代码:
public class TabWorkEntryActivity extends TabActivity {
//hide tabs
private OnClickListener tabClickListener = new OnClickListener() {
public void onClick(View v) {
if (v.getVisibility() == View.VISIBLE) {
v.setVisibility( View.INVISIBLE );
} else {
v.setVisibility( View.VISIBLE );
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabworkentry);
TabHost mTabHost = getTabHost();
//get width of the display
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
mTabHost.addTab(mTabHost.newTabSpec("top10").setIndicator("Top 10").setContent(R.id.textview1));
mTabHost.addTab(mTabHost.newTabSpec("billable").setIndicator("Billable").setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("product").setIndicator("Product").setContent(R.id.textview3));
mTabHost.addTab(mTabHost.newTabSpec("regular").setIndicator("Regular").setContent(R.id.textview4));
mTabHost.setCurrentTab(3);
mTabHost.getTabWidget().getChildAt(0).setLayoutParams(new
LinearLayout.LayoutParams(((width/9)*2),50));
mTabHost.getTabWidget().getChildAt(1).setLayoutParams(new
LinearLayout.LayoutParams(((width/9)*2),50));
mTabHost.getTabWidget().getChildAt(2).setLayoutParams(new
LinearLayout.LayoutParams(((width/9)*2),50));
mTabHost.getTabWidget().getChildAt(3).setLayoutParams(new
LinearLayout.LayoutParams(((width/9)*2),50));
// 代码中的其他位置... mTabHost.setOnClickListener( tabClickListener ); } }
由于某种原因,此代码不起作用。有人可以帮忙吗。