我有一个带有xml布局的DialogFragment
,我需要它的宽度只占屏幕的75%。当我寻找答案时,我经常会发现普遍的weight
解决方案,并不能帮助我,因为我的片段覆盖了当前活动,如下图所示,并没有占满整个屏幕的大小。我也不想使用“ems”作为固定宽度,因为我无法知道用户的屏幕尺寸。
有没有一种方法(最好是在xml中)来将根LinearLayout
的宽度设置为所需的75%?我认为定义一组完整的LinearLayout
并使其中一些透明可能是一种解决方法,但这似乎是一种相当丑陋的解决方案...
如果有用的话,这是片段的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_height = "wrap_content"
android:layout_width = "match_parent"
android:orientation = "vertical" >
<EditText
android:hint = "@string/inputhint_feedbackName"
android:id = "@+id/input_feedbackName"
android:imeOptions = "actionNext"
android:inputType = "textPersonName"
android:layout_height = "wrap_content"
android:layout_width = "match_parent"
android:lines = "1"
android:maxLines = "1"
android:singleLine = "true" >
<requestFocus />
</EditText>
<EditText
android:gravity = "top"
android:id = "@+id/input_feedbackMessage"
android:imeOptions = "actionDone"
android:layout_height = "wrap_content"
android:layout_marginBottom = "20dp"
android:layout_width = "match_parent"
android:lines = "10"
android:inputType = "textMultiLine" />
<Button
android:id = "@+id/button_feedbackSend"
android:layout_height = "wrap_content"
android:layout_width = "match_parent"
android:text = "@string/label_go"
android:textSize = "16sp"
android:textStyle = "bold" />
</LinearLayout>
onCreateView()
中添加了相同的代码,但没有任何反应。只有在将其添加到onResume()
后才起作用。为安卓干杯!! - iCantC