【问题标题】:LinearLayout Weight issue线性布局权重问题
【发布时间】:2014-11-30 02:13:12
【问题描述】:

好吧,我在 ScrollView 中有一个垂直 LinearLayout,它是我注册付款的一种形式,要点比我试图让它响应,这个列表视图中的每一件事都会有一个垂直权重1,为了让元素在这个LinearLayout的保留空间上得到公平的参与,关键是linearLayout不识别“match_parent”元素,它是列表视图

<ScrollView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:id="@+id/scrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="5dp"
            android:divider="@drawable/divider_one"
            android:showDividers="middle"
            android:dividerPadding="5dp">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="vertical"
                android:layout_weight="1">

                <RadioGroup
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="horizontal"
                    android:id="@+id/concept_group">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:text="Gasto De:"
                        android:id="@+id/textView4"
                        android:layout_weight="1" />

                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Materia Prima"
                        android:id="@+id/materialButton"
                        android:layout_weight="1" />

                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Otro Concepto"
                        android:id="@+id/otrosButton"
                        android:layout_weight="1" />
                </RadioGroup>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                android:layout_weight="1">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="Monto: "
                    android:id="@+id/textView5"
                    android:layout_weight="1" />

                <EditText
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:inputType="numberDecimal"
                    android:ems="10"
                    android:id="@+id/montoEditText"
                    android:layout_weight="3" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                android:layout_weight="1"
                android:id="@+id/rowConcepto">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:id="@+id/conceptTextView"
                    android:layout_weight="1" />
            </LinearLayout>

           <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:orientation="horizontal"
               android:layout_weight="1"
               android:layout_gravity="center"
               android:gravity="center">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Registrar"
                    android:id="@+id/registrarButton"
                    android:layout_weight="0"
                    android:gravity="center"/>
           </LinearLayout>

        </LinearLayout>
    </ScrollView>

希望你明白我的意思,如果有任何帮助,我将不胜感激

【问题讨论】:

  • 哪个列表视图,不,我不明白你的意思。能具体点吗?

标签: android android-layout android-linearlayout


【解决方案1】:

尝试在您的父级 LinearLayout 上执行此操作

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="3">  

将权重加到 3

不知道行不行:/
你应该给它一个打击。

编辑:
尝试在您的 ScrollView 中添加它

android:fillViewport="true"

【讨论】:

  • @MaToXz 你的意思是它没有填满整个屏幕?
  • 问题是,我有一个线性布局,里面还有 2 个线性布局,里面的每个布局都有 1 的 layout_weight,我的意思是我把屏幕分成两个相等的线性布局,里面前半部分线性布局,我有那个代码,我正在显示的列表视图
  • @MaToXz 尝试将 fillViewport 添加到 ScrollView,您可以在我编辑的答案中看到
猜你喜欢
  • 1970-01-01
  • 2017-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多