Android 安卓按钮高度
我创建了一组垂直选项卡,使用按钮表示选项卡,并设置了按钮的高度以包装内容 这一点似乎没有得到尊重,尽管按钮的缩放会占用所有可用空间,但在垂直线性布局中只有5个按钮,但它们都会拉伸以占用可用空间。按钮中的图标很小,文本也很小,所以看起来不太好 如何让按钮真正只包装其内容?我希望他们都一样大小,不要填满所有可用的空间 在dp中明确设置高度是好主意还是坏主意Android 安卓按钮高度,android,button,layout,Android,Button,Layout,我创建了一组垂直选项卡,使用按钮表示选项卡,并设置了按钮的高度以包装内容 这一点似乎没有得到尊重,尽管按钮的缩放会占用所有可用空间,但在垂直线性布局中只有5个按钮,但它们都会拉伸以占用可用空间。按钮中的图标很小,文本也很小,所以看起来不太好 如何让按钮真正只包装其内容?我希望他们都一样大小,不要填满所有可用的空间 在dp中明确设置高度是好主意还是坏主意 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.app.
<?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>
谢谢按钮的布局重量参数是导致您出现问题的原因。如果设置了此参数,则忽略高度参数。设置权重会将所有剩余空间分配给所有权重为其权重比率的孩子。在布局中,有6个按钮。因此,剩余空间由6个按钮填充,所有按钮的高度设置相同。可以限制线性布局父级的高度,也可以删除按钮的权重。
编辑:我已经提到,如果设置了重量,则忽略高度。仅当线性布局的方向是垂直的时,此情况才成立。如果是水平的,则忽略宽度属性。按钮的布局权重参数是导致问题的原因。如果设置了此参数,则忽略高度参数。设置权重会将所有剩余空间分配给所有权重为其权重比率的孩子。在布局中,有6个按钮。因此,剩余空间由6个按钮填充,所有按钮的高度设置相同。可以限制线性布局父级的高度,也可以删除按钮的权重。
编辑:我已经提到,如果设置了重量,则忽略高度。仅当线性布局的方向是垂直的时,此情况才成立。如果是水平的,则忽略宽度属性。在dp中设置高度将无法在不同屏幕中保持完美的比例 对我来说,最简单的方法是通过代码创建接口,这样我就可以进行任何需要的计算,并在px上设置精确的大小 看看征求意见 至于固定xml,请将LinearLayout height设置为包裹内容或移除权重,这样可以使按钮平均分配父级高度
希望这有帮助。在dp中设置高度不会在不同的屏幕中保持完美的比例 对我来说,最简单的方法是通过代码创建接口,这样我就可以进行任何需要的计算,并在px上设置精确的大小 看看征求意见 至于固定xml,请将LinearLayout height设置为包裹内容或移除权重,这样可以使按钮平均分配父级高度
希望这能有所帮助。您能发布您的xml布局吗?对于包含文本的内容,明确设置高度通常不是一个好主意,因为用户可以在应用程序之外缩放全局文本大小。要回答其余问题,您需要发布一些代码-您的布局应该足够了,但我们可能需要更多_0好的,我已经添加了xml布局,希望足够了!您可以发布您的xml布局吗?对于包含文本的内容,显式设置高度通常不是一个好主意,因为用户可以在应用程序之外缩放全局文本大小。要回答其余问题,您需要发布一些代码-您的布局应该足够了,但我们可能需要更多_0好的,我已经添加了xml布局,希望足够了!非常感谢你帮我卸下固定的重量,可惜我不能接受多个答案,但再次感谢你的快速回复!非常感谢你帮我卸下固定的重量,可惜我不能接受多个答案,但再次感谢你的快速回复!