New*_*Guy 38 android android-layout
我见过几个使用android的例子:layout_height ="0px"或"0dip",但我不明白这个的影响.似乎这将使布局高0像素.是否减轻了价值,但还有一些其他因素,如"权重"或任何父视图的高度?
Nat*_*ann 35
你是否正确的权重,当你想要按重量控制宽度或高度时,将该值设置为0dip并让重量控制实际值.虽然我很确定0在这里是任意的,你可以放任何东西,但是把0放在一起会让你的意图更清晰.
Fem*_*emi 11
如果将LinearLayout设置为layout_weight
非零值并将layout_height
(或layout_width
)设置为0px或0dip,则LinearLayout会根据权重沿适当的轴分配任何未分配的空间.因此,例如,如果您查看带有id*layout_height
gestures_overlay*的View下面的布局,它有0dip和layout_weight
1,因此父LinearLayout会拉伸它以填充2个周围LinearLayouts之间的可用垂直空间.如果存在具有相同0dip layout_height
和layout_weight
值的另一个视图,则它们将基于它们的权重值共享垂直空间.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:text="@string/prompt_gesture_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/gesture_name"
android:layout_width="0dip"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:maxLength="40"
android:singleLine="true" />
</LinearLayout>
<android.gesture.GestureOverlayView
android:id="@+id/gestures_overlay"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:gestureStrokeType="multiple" />
<LinearLayout
style="@android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/done"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:onClick="addGesture"
android:text="@string/button_done" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="cancelGesture"
android:text="@string/button_discard" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17724 次 |
最近记录: |