我已经制作了一个可重复使用的视图,由一组按钮组成。
我试图让按钮填满屏幕的整个宽度,但它无法正常工作。下面是我的XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Navi" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layout1"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:weightSum="8">
<Button
android:id="@+id/button0"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Start" />
<Button
android:id="@+id/button1"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Observation" />
<Button
android:id="@+id/button2"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Joint Integrity Tests" />
<Button
android:id="@+id/button3"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Active Movements" />
<Button
android:id="@+id/button4"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Passive Movements" />
<Button
android:id="@+id/button5"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Repeated Movements" />
<Button
android:id="@+id/button6"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Combined Movements" />
<Button
android:id="@+id/button7"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Capsular Pattern" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:weightSum="8">
<Button
android:id="@+id/button8"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Joint Effusion" />
<Button
android:id="@+id/button9"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="PPIVMs" />
<Button
android:id="@+id/button10"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Other Joints Involved" />
<Button
android:id="@+id/button11"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Muscle Strength" />
<Button
android:id="@+id/button12"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Muscle Control" />
<Button
android:id="@+id/button13"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Muscle Length" />
<Button
android:id="@+id/button14"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Isometric Muscle Tests" />
<Button
android:id="@+id/button15"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Integrity Of Nervous System" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:weightSum="8">
<Button
android:id="@+id/button16"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Mobility Of Nervous System" />
<Button
android:id="@+id/button17"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Diagnostic Tests" />
<Button
android:id="@+id/button18"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Special Tests" />
<Button
android:id="@+id/button19"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Accessory Movements" />
<Button
android:id="@+id/button20"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Palpation" />
<Button
android:id="@+id/button21"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Conclusion" />
<Button
android:id="@+id/button22"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="Diagnosis" />
<Button
android:id="@+id/button23"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="Previous"
android:text="End" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
以下是我用来导入视图的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Observation" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="108dp" />
<include layout="@layout/navigation"
android:layout_width="fill_parent"/>
</RelativeLayout>
答案 0 :(得分:0)
您只提到android:layout_width="fill_parent"
你需要添加宽度和宽度达到这个效果的高度。
However, if you want to override layout attributes using the <include> tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.
此外,您应该使用match_parent
代替fill_parent
但是,您还没有提到您遇到的确切问题,但我仍然猜测如果您看到所包含布局的所有方面都留下了一些空间,那么代码中的以下内容可能就是问题,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Navi" >
你正在给它填充。
机器人:paddingBottom来=&#34; @扪/ activity_vertical_margin&#34; 机器人:paddingLeft =&#34; @扪/ activity_horizontal_margin&#34; 机器人:paddingRight =&#34; @扪/ activity_horizontal_margin&#34; 机器人:paddingTop =&#34; @扪/ activity_vertical_margin&#34;
尝试从RelativeLayout
标记