簡體   English   中英

帶有浮動按鈕的Android linearlayout

[英]Android linearlayout with floating button

我嘗試在我的主要xml中使浮動按鈕成為包含我的項目列表的linearlayout(我知道我可以使用列表視圖,但由於我的任務我需要使用linearlayout方法)。 我所有的嘗試都一直失敗,因為按鈕適合在linearlayout中使用的文本行內。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:id="@+id/infofo"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    android:gravity="center_vertical"
    android:text="test" />

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button" />
</LinearLayout>

如果有人可以幫助我實現這一目標,我將非常高興。 謝謝。

編輯-

這就是問題所在,解決方案只需要將屏幕底部的一個按鈕作為浮動操作按鈕即可。 問題

無論您放置在垂直LinearLayout中的內容是什么,都將在其他元素下方繪制。 您應該在能夠處理此問題的另一個Layout內的LinearLayout旁邊添加Floating按鈕(例如FrameLayout,RelativeLayout,CoordinatorLayout等)

<?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" >
    <LinearLayout
      android:layout_width="wrap_content"
      android:id="@+id/infofo"
      android:layout_height="wrap_content"
      android:orientation="vertical">

      <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:gravity="center_vertical"
        android:text="test" />

    </LinearLayout>

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

</RelativeLayout>

暫無
暫無

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

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