mar*_*ike 8 xml android android-layout
我为我的一些屏幕创建了一个android布局xml,显然我在我的应用程序中使用导航抽屉,这就是我使用框架布局的原因.现在我添加了一个线性布局,它将显示以下内容:
带有提交按钮的文本视图
2个图像按钮
这是我想要的示例布局:
问题是当我进行布局时,我似乎无法拉下2个按钮使它们位于提交下方,因为发生的情况是两个按钮都位于布局的右侧,如下所示:
这是我的xml代码:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="mypackage.test.HomeActivity" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linerlayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center_horizontal"
>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter ID"
>
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
<!--
I'm trying to put the two buttons here but what happens is they both disappear when I put them
-->
<Button
android:id="@+id/button2"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button3"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
<fragment
android:id="@+id/navigation_drawer"
android:name="mypackage.test.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
如何拉下两个按钮?我应该将按钮转移到另一个布局吗?
您可以将另外两个按钮放在LinearLayout布局之外,以便它们显示在底部.像这样:
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linerlayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center_horizontal"
>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter ID"
>
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
<Button
android:id="@+id/button3"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"/>
<Button
android:id="@+id/button2"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19248 次 |
最近记录: |