android - fragment 内容被切断

标签 android android-layout

我目前正在开发一款 Android 游戏。我的 fragment 中的内容有问题。内容被切断,我找不到问题所在。我只使用资源目录,我在其中定义了不同的布局。这就是为什么我知道问题出在布局上。首先,我认为这与我使用 android:layout_height="match_parent" 这一事实有关。我在 StackOverflow 上找到了这个解决方案,我希望它也能解决我的问题。但这对我一点帮助都没有。

我有 activity_game.xml。我有一个当前显示的 Fragment 的占位符。内容如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="y.trader.com.rhcloud.blackmonster.games.tradery.activity.GameActivity">

  <FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</RelativeLayout>

Fragment 本身定义了以下布局:

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

  <TextView
    android:id="@+id/money"
    style="@style/traderY.TextCenter" />

  <TextView
    android:id="@+id/location"
    style="@style/traderY.TextCenter" />

  <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/junkie_icon"/>

  <ListView
    android:id="@+id/drug_list"
    style="@style/traderY.List" />

  <TableRow
    style="@style/traderY.ButtonRow">

    <Button
        android:id="@+id/sell_drugs"
        style="@style/traderY.ButtonCenter"
        android:text="@string/sell"/>

    <Button
        android:id="@+id/nothing"
        style="@style/traderY.ButtonCenter"
        android:text="@string/nothing"/>

  </TableRow>

</LinearLayout>

这是显示问题的捕获屏幕。

Screen capture

如您所见,最后两个按钮被剪掉了。我想避免这种情况,而是允许用户向下滚动。我在一个死的情况下,我会很感激任何帮助。我希望我能够很好地解释这个问题,以便于理解。

最佳答案

在不使用ScrollView的情况下,您可以为ListView设置weight。试试这个解决方案:

 <ListView
    ...
    android:layout_weight="1"/>

关于android - fragment 内容被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36707624/

相关文章:

android - 我可以将 android 应用程序的背景作为一组图像吗?

android - 如何在包含 Android 布局的同时访问其绑定(bind)中的元素?

android - 在图表引擎 android 中显示条形图 y 轴的网格线

Android:是否可以在屏幕上同时创建底部和顶部选项卡?

android - Twilio Video - 调用参与者加入视频通话

java - 如何知道异步任务何时完成

Android - 更改高度时阴影大小不受影响

java - 如何在 android 中将这些数字对齐到小数点?

android - 键盘出现时平滑滚动布局?

Android 备份/恢复 : how to backup an internal database?