我正在研究android應用程序有tabs.I已完成實施,但我面臨一個問題。圖像不適合選項卡。Android選項卡圖像不適合選項卡
這裏是我的Java代碼:
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import com.tv.allies.FriendsScreen;
import com.tv.servercommunication.IServerResponse;
import com.tv.setting.SettingActivity;
import com.tv.socialgoal.R;
import com.tv.socialgoal.profile.ProfileScreen;
import com.tv.task.TaskListActivity;
@SuppressWarnings("deprecation")
public class TabViewActivity extends TabActivity implements IServerResponse{
private static final String INBOX_SPEC = "Inbox";
private static final String OUTBOX_SPEC = "Outbox";
private static final String PROFILE_SPEC = "Profile";
private static final String SETTING_SPEC = "Setting";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost
.newTabSpec("one")
.setIndicator("",
getResources().getDrawable(R.drawable.missions_btn_up))
.setContent(
new Intent(this, TaskListActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
TabSpec outboxSpec = tabHost.newTabSpec(OUTBOX_SPEC);
tabHost.addTab(tabHost
.newTabSpec("two")
.setIndicator("",
getResources().getDrawable(R.drawable.allies_btn_up))
.setContent(new Intent(this, FriendsScreen.class)));
TabSpec setting = tabHost.newTabSpec(OUTBOX_SPEC);
outboxSpec.setIndicator("",getResources().getDrawable(R.drawable.profile_btn_up));
Intent outboxIntent = new Intent(this, ProfileScreen.class);
outboxSpec.setContent(outboxIntent);
// Profile Tab
TabSpec profileSpec = tabHost.newTabSpec(PROFILE_SPEC);
profileSpec.setIndicator("",getResources().getDrawable(R.drawable.settings_btn_up));
Intent profileIntent = new Intent(this, SettingActivity.class);
profileSpec.setContent(profileIntent);
tabHost.addTab(outboxSpec); // Adding Outbox tab
tabHost.addTab(profileSpec);
}
@Override
public void serverResponse(String response, int processid) {
// TODO Auto-generated method stub
}
}
這裏是標籤的xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#3399FF"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
這裏是屏幕短:
所有標籤圖像如何適合每個標籤?
嗨我正在使用正確的圖像標籤。 –
@ricintech檢查此http://www.androidhive.info/2011/08/android-tab-layout-tutorial/ – sachin10