【发布时间】:2015-10-08 16:47:16
【问题描述】:
我创建了一组使用按钮来表示选项卡的垂直选项卡,并设置了按钮的高度以包裹内容。
这似乎没有得到尊重,尽管按钮缩放以占用所有可用空间,垂直线性布局中只有 5 个按钮,但它们都拉伸以占用可用空间。按钮中的图标很小,文字也很小,所以看起来不太好。
如何让按钮真正只包装其内容?我希望它们都具有相同的大小,并且不会填满所有可用空间。
在 dp 中明确设置高度是好主意还是坏主意?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_grey">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="8dp">
<FrameLayout android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="3">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/tab_btn_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/patient_tab_btn"
android:text="Patient"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/user"
android:paddingTop="4dp"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/relations_tab_btn"
android:text="Relations"
android:layout_marginTop="1dp"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/family"
android:paddingTop="4dp"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/providers_tab_btn"
android:text="Providers"
android:layout_marginTop="1dp"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/doctors_bag"
android:paddingTop="4dp"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/locations_tab_btn"
android:text="Locations"
android:layout_marginTop="1dp"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/map_marker"
android:paddingTop="4dp"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/summary_tab_btn"
android:text="Summary"
android:layout_marginTop="1dp"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/treatment_plan"
android:paddingTop="4dp"
/>
<Button
android:layout_height="|"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:background="@color/lightest_grey"
android:id="@+id/cpis_tab_btn"
android:text="Protection"
android:layout_marginTop="1dp"
android:textSize="7sp"
android:gravity="bottom|center"
android:drawableTop="@drawable/students"
android:paddingTop="4dp"
/>
</LinearLayout>
</FrameLayout>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="17"
android:background="@color/white"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
谢谢
【问题讨论】:
-
你能发布你的xml布局吗?
-
显式设置高度对于包含文本的内容通常不是一个好主意,因为用户可以在您的应用程序之外缩放全局文本大小。要回答其余的问题,您需要发布一些代码 - 您的布局应该足够了,但我们可能需要更多;_0
-
好的,我已经添加了xml布局,希望够用了!