android-减少标签高度并在顶部对齐文本?

android-减少标签高度并在顶部对齐文本?,第1张

概述如何减少标签的高度并在顶部对齐文本?importandroid.app.TabActivity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.widget.TabHost;publicclassMessagesTabsextendsTabActivity{publicvoidonCreate(BundlesavedInstanceState){

如何减少标签的高度并在顶部对齐文本?

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);    }}

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: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>

解决方法:

只需尝试增加标签的高度即可:

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

对于文本对齐,请在xml布局中尝试以下 *** 作:

androID:gravity =“ top”或androID:layout_gravity =“ top”

总结

以上是内存溢出为你收集整理的android-减少标签高度并在顶部对齐文本?全部内容,希望文章能够帮你解决android-减少标签高度并在顶部对齐文本?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存