繁体   English   中英

为什么在文本换行时带权重的textview的高度无效?

[英]Why does textview with weight have invalid height in case of text wrapping?

我有一个对话框,其中包含布局xml。 控件是垂直对齐的,并且在一个“行”中有一个textview和一个seekbar。 Textview的weight=1 ,而搜寻栏的weight=1 weight=2

现在的问题是,如果textview无法容纳,则会自动换行,但不会调整textview的高度,并且第二行不可见。

布局xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

  <LinearLayout 
    android:id="@+id/dialog_settings_layout_main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="240dp"
    android:padding="10dp"
    android:orientation="vertical" >

    ....other controls.....

    <LinearLayout 
    android:id="@+id/dialog_settings_layout_volume"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView_dialog_settings"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="aaaaaaaaa bbbbbbbbbb cccccccccc"
        android:layout_gravity="center_vertical"
        android:paddingRight="20dp"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <SeekBar
        android:id="@+id/seekbar_dialog_settings"
        android:layout_width="0px"
        android:layout_weight="2"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:max="8"
        android:progress="1" />

    </LinearLayout>

    ....other controls.....

好吧,我想我有解决办法。

设置match_parentScrollView宽度和高度以及水平LinearLayout宽度。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

  <LinearLayout 
    android:id="@+id/dialog_settings_layout_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="240dp"
    android:padding="10dp"
    android:orientation="vertical" >

我试图重现它,并且一切正常,直到我用ScrollView包装了布局,而我一开始就错过了。 然后我遇到了完全相同的问题,调整提到的值解决了它。

更新资料

要使其在Dialog中工作,请使用AlertDialog.Builder创建一个

AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.dialog_layout, null);
builder.setView(view);
AlertDialog dialog = builder.create();

dialog.show();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM