【问题标题】:Showing button below a fragment in an activity在活动中的片段下方显示按钮
【发布时间】:2012-07-09 16:46:24
【问题描述】:

我对 Android 还是很陌生。我有一个非常简单的布局,但还不能工作:

<LinearLayout android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/relativeLayout">
    <fragment android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:name="pl.nscr.playwatch.MainActivity$WatchListFragment"
          android:id="@+id/watchlist"/>
    <Button android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Start service"/>
</LinearLayout>

现在我的问题是片段跨越了活动中的整个可用高度。我希望能够看到它下面的那个按钮,但我实际上不知道如何布局这个东西。

我尝试使用RelativeLayout,但最终显示在片段上方的按钮看起来很难看。我做错了什么?

更新

显然这是一个愚蠢的错误。我再次改回RelativeLayout,但现在布局的宽度和高度设置为“fill_parent”,一切正常。

<RelativeLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/relativeLayout">
    <fragment android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:name="pl.nscr.playwatch.MainActivity$WatchListFragment"
            android:id="@+id/watchlist"
            android:layout_above="@+id/btnStartService"/>
    <Button android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:id="@id/btnStartService"
            android:text="Start service"/>
</RelativeLayout>

【问题讨论】:

    标签: android layout


    【解决方案1】:

    执行以下操作

    1. 将 android:orientation="vertical" 属性添加到&lt;LinearLayout&gt;
    2. 将 layout_weight="1" 属性添加到&lt;fragment /&gt;

    【讨论】:

      【解决方案2】:

      android:orientation="vertical" 添加到LinearLayout..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-09
        相关资源
        最近更新 更多