【问题标题】:Descendents layouts not appearing后代布局未出现
【发布时间】:2014-12-16 12:38:11
【问题描述】:

我正在尝试定义多个 LinearLayout 以适应我的活动底部的表单和按钮栏,但它没有出现,在我更改之前,所有表单都使用 ScrollView,但我删除了它,因为我将不再使用,但是当我删除我的布局不再出现时,任何人有任何解决方案我做错了什么?还是忘了?

这是我的新代码,但是当我将方向转为横向时,我的按钮消失了。我该如何解决?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Cliente:  "
            android:textSize="18sp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
                android:id="@+id/nota_cliente"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="2"
                android:imeOptions="flagNoExtractUi|actionSearch"
                android:inputType="textCapSentences" />

            <ProgressBar
                android:id="@+id/nota_cliente_loading_indicator"
                style="?android:attr/progressBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|end"
                android:layout_marginEnd="@dimen/margin_default"
                android:visibility="gone" />
        </FrameLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Dados do Dispositivo:  "
            android:textSize="18sp" />

        <Spinner
            android:id="@+id/dadosdispo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Número de Série:  "
            android:textSize="18sp" />

        <EditText
            android:id="@+id/nota_numeroserie"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Digite o n° serie"
            android:maxLength="18" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Descrição: "
            android:textSize="18sp" />

        <EditText
            android:id="@+id/nota_descricao"
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:hint="Digite a descrição"
             />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center|bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btn_nota_itenslist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Itens" />

    <Button
        android:id="@+id/btn_nota_ordenslist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Ordens" />

    <Button
        android:id="@+id/btn_nota_limpar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Limpar" />

    <Button
        android:id="@+id/btn_nota_salvar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Salvar" />
</LinearLayout>

</LinearLayout>

这就是我想要的,但是当切换横向模式时,我的按钮不会消失,我可以通过这种方式弄清楚但我不知道是否正确。

并带有标签android:gravity="center|bottom" 我希望在我的活动的last line 中设置这些栏按钮,最后一个小部件栏可以这样说,但我不知道如何?

另外,我怎样才能将按钮的大小分开以适应屏幕的大小?

【问题讨论】:

  • 你能发一张你想要的照片吗?
  • 当然刚刚更新...
  • 你发布的xml是当前那个?
  • 是的,我现在用的是这个,我需要解决更改屏幕尖/纵向 x 横向和按钮大小的问题
  • @TheRedFox 你有什么想法我能做什么???

标签: android android-layout android-linearlayout android-relativelayout android-framelayout


【解决方案1】:

只需将layout_height0dp 更改为ScrollView0dp 应用权重1 不适用于LinearLayout(在ScrollView 中)这样做

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Cliente:  "
                android:textSize="18sp" />

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
                    android:id="@+id/nota_cliente"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="2"
                    android:imeOptions="flagNoExtractUi|actionSearch"
                    android:inputType="textCapSentences" />

                <ProgressBar
                    android:id="@+id/nota_cliente_loading_indicator"
                    style="?android:attr/progressBarStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|end"
                    android:layout_marginEnd="@dimen/margin_default"
                    android:visibility="gone" />
            </FrameLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Dados do Dispositivo:  "
                android:textSize="18sp" />

            <Spinner
                android:id="@+id/dadosdispo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Número de Série:  "
                android:textSize="18sp" />

            <EditText
                android:id="@+id/nota_numeroserie"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="Digite o n° serie"
                android:maxLength="18" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Descrição: "
                android:textSize="18sp" />

            <EditText
                android:id="@+id/nota_descricao"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:hint="Digite a descrição" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center|bottom"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_nota_itenslist"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="3dp"
            android:background="@drawable/button_selector"
            android:text="Itens" />

        <Button
            android:id="@+id/btn_nota_ordenslist"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="3dp"
            android:background="@drawable/button_selector"
            android:text="Ordens" />

        <Button
            android:id="@+id/btn_nota_limpar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="3dp"
            android:background="@drawable/button_selector"
            android:text="Limpar" />

        <Button
            android:id="@+id/btn_nota_salvar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="3dp"
            android:background="@drawable/button_selector"
            android:text="Salvar" />
    </LinearLayout>
</LinearLayout>

【讨论】:

  • 哦,非常感谢,它可以工作,并且使用这个 xml 我正在填充一个片段,实际上当我的应用程序启动时,以纵向模式启动,但如果改变视角,我的应用程序会崩溃吗知道为什么会这样吗?
【解决方案2】:
Try Relative Layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/linear"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Cliente:  "
            android:textSize="18sp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <br.com.stara.iris.mobile.tmp.DelayAutoCompleteTextView
                android:id="@+id/nota_cliente"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="2"
                android:imeOptions="flagNoExtractUi|actionSearch"
                android:inputType="textCapSentences" />

            <ProgressBar
                android:id="@+id/nota_cliente_loading_indicator"
                style="?android:attr/progressBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|end"
                android:layout_marginEnd="@dimen/margin_default"
                android:visibility="gone" />
        </FrameLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Dados do Dispositivo:  "
            android:textSize="18sp" />

        <Spinner
            android:id="@+id/dadosdispo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Número de Série:  "
            android:textSize="18sp" />

        <EditText
            android:id="@+id/nota_numeroserie"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Digite o n° serie"
            android:maxLength="18" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Descrição: "
            android:textSize="18sp" />

        <EditText
            android:id="@+id/nota_descricao"
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:hint="Digite a descrição" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center|bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btn_nota_itenslist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Itens" />

    <Button
        android:id="@+id/btn_nota_ordenslist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Ordens" />

    <Button
        android:id="@+id/btn_nota_limpar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Limpar" />

    <Button
        android:id="@+id/btn_nota_salvar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_selector"
        android:text="Salvar" />
</LinearLayout>

</RelativeLayout>

【讨论】:

  • 哦,非常感谢,它可以工作,并且使用这个 xml 我正在填充一个片段,实际上当我的应用程序启动时,以纵向模式启动,但如果改变视角,我的应用程序会崩溃吗知道为什么会这样吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-05
  • 1970-01-01
  • 2019-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多