减少标签的高度和顶部对齐文本? [英] Reduce Tab height and align text on top?

查看:110
本文介绍了减少标签的高度和顶部对齐文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何降低标签的高度和顶部对齐文本?

 进口android.app.TabActivity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.widget.TabHost;公共类MessagesTabs扩展TabActivity {    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.messages_tabs);        //资源解析度= getResources(); //资源对象获取可绘制
        TabHost tabHost = getTabHost(); //活动TabHost
        TabHost.TabSpec规范; // Resusable则tabspec为每个标签
        意图意图; //可重用的意图为每个标签        //创建一个Intent来启动一个活动的标签(重复使用)
        意图=新意图()setClass(这一点,GetMessages.class)。        //初始化则tabspec每个选项卡,并把它添加到TabHost
        规格= tabHost.newTabSpec(收件箱)setIndicator。(收件箱)
        .setContent(意向);
        tabHost.addTab(规范);        //做其他选项卡相同
        意图=新意图()setClass(这一点,GetConversations.class)。
        规格= tabHost.newTabSpec(对话)。setIndicator(对话)
        .setContent(意向);
        tabHost.addTab(规范);
        / *
        意图=新意图()setClass(这一点,SongsActivity.class)。
        规格= tabHost.newTabSpec(诗经)。setIndicator(诗经,
                          res.getDrawable(R.drawable.ic_tab_songs))
                      .setContent(意向);
        tabHost.addTab(SPEC); * /        tabHost.setCurrentTab(0);
    }
}

XMLFILE

 <?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        >
        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT/>
        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
             />    < / LinearLayout中>< / TabHost>


解决方案

只是尝试一下本作增加了标签的高度:

  tabHost.getTabWidget()getChildAt(指数).getLayoutParams()=身高(INT)高度。

对于文本对齐试试这个在你的XML布局:

安卓重力=顶的android:layout_gravity =顶

how can i Reduce Tab height and align text on top?

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class MessagesTabs extends TabActivity{

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.messages_tabs);

        //Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, GetMessages.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("inbox").setIndicator("Inbox")
        .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, GetConversations.class);
        spec = tabHost.newTabSpec("conversation").setIndicator("Conversation")
        .setContent(intent);
        tabHost.addTab(spec);
        /*
        intent = new Intent().setClass(this, SongsActivity.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Songs",
                          res.getDrawable(R.drawable.ic_tab_songs))
                      .setContent(intent);
        tabHost.addTab(spec);*/

        tabHost.setCurrentTab(0);
    }


}

xmlfile

<?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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <TabWidget          
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             />

    </LinearLayout>

</TabHost>

解决方案

just try this for increasing the height of the tabs :

 tabHost.getTabWidget().getChildAt(index).getLayoutParams().height =(int) height;

for text aligning try this in your xml layout :

android:gravity="top" or android:layout_gravity="top"

这篇关于减少标签的高度和顶部对齐文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆