【问题标题】:Android frame layout in xmlxml中的Android框架布局
【发布时间】:2013-10-12 17:50:25
【问题描述】:

我有一个框架布局,其中有一个列表视图、编辑文本和一个按钮,但现在我想在列表视图上方布局的右上角放置一个按钮,但我遇到了问题。我的xml是:

<?xml version="1.0" encoding="utf-8"?>
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

      <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="86dp"
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Send" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/button1"
        android:ems="10" />

  </RelativeLayout>

  <ListView
      android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="317dp" >

  </ListView>

        </FrameLayout>

【问题讨论】:

  • 您似乎忘记描述您遇到的问题,
  • 我想在布局的右上角添加按钮,但无法做到。
  • 您正在寻找的结果的屏幕截图会有所帮助。
  • 请检查我的编辑问题

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


【解决方案1】:

FrameLayouts 被设计成通常只包含一个子元素。它们有点像外卡。因此,我建议您使用它的发布方式。而是将相对布局设为根布局。

以下是如何实现该功能的示例。

图片:

代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
  <Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:text="NEW BUTTON!" />

  <ListView
   android:id="@+id/list"
   android:layout_width="match_parent"
   android:layout_height="317dp" 
   android:layout_below="@+id/button2">
  </ListView>

  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Send" />

  <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/list"
    android:layout_toLeftOf="@+id/button1"
    android:ems="10" />

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多