Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如果按钮为';水平直线布局中微调器后的s_Android_Android Layout_Android Fragments_Xamarin.android - Fatal编程技术网

Android 如果按钮为';水平直线布局中微调器后的s

Android 如果按钮为';水平直线布局中微调器后的s,android,android-layout,android-fragments,xamarin.android,Android,Android Layout,Android Fragments,Xamarin.android,我在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&

我在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" />

但我需要按钮位于右上角,因此我尝试将其放置在同一水平线性布局中的微调器之后(这里仅提供嵌套线性布局的代码):


在那次更改之后,布局看起来很奇怪:

这里怎么了?为什么巴顿会这样?我怎样才能解决这个问题

编辑: 上面的布局代码是一个片段。下面是我使用此片段的活动代码:

<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)或包裹内容进行调整,它将正常工作

<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>