簡體   English   中英

如果按鈕在水平線性布局中的微調器之后,則無法正確顯示

[英]Button is not showing correctly if it's after spinner in horizontal linearlayout

我使用以下代碼在 xamarin 中有一個適用於 android 的 axml 布局:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.Space
    android:layout_width="match_parent"
    android:layout_height="20px"
    android:id="@+id/space1" />
<LinearLayout
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout1">
    <TextView
        android:text="Text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/text"
        android:paddingLeft="25px"
        android:paddingTop="10px"
        android:paddingRight="15px" />
    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/button1" />
    <Spinner
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="15px"
        android:id="@+id/spinner" />
    
</LinearLayout>
<Space
    android:layout_width="match_parent"
    android:layout_height="25px"
    android:id="@+id/space2" />
<EditText
    android:gravity="top"
    android:hint="long text"    
    android:inputType="textLongMessage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/editText1" />

它正在發揮作用。

布局之前

但是我需要按鈕位於右上角,所以我嘗試將它放在同一個水平線性布局中的微調器之后(這里僅是嵌套線性布局的代碼):

<LinearLayout
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout1">
    <TextView
        android:text="Text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/text"
        android:paddingLeft="25px"
        android:paddingTop="10px"
        android:paddingRight="15px" />
    <Spinner
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="15px"
        android:id="@+id/spinner" />
    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/button1" />
</LinearLayout>

在更改布局之后看起來很奇怪:

布局后

這里有什么問題? 為什么按鈕會發生這種情況? 我怎樣才能解決這個問題?

編輯:上面的布局代碼是一個片段。 這是我使用此片段的活動代碼:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    
        <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:background="?attr/colorPrimaryDark">
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

這種布局是由微調器中的高度匹配父級引起的,因為它占用了所有空間並且不讓按鈕有任何位置。 如果您使用固定大小(如 150dp)或包裝內容調整它,它將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM