我正在开发具有标签的 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>
这是屏幕短:
所有标签图像如何适合每个标签?