android – 片段内容被切断

我目前正在开发
Android游戏.我在Fragment中的内容有问题.内容被切断,我无法找到问题.我只使用资源目录,在那里我定义了不同的布局.这就是为什么我知道问题在于布局.首先我认为它与我使用android的事实有关:layout_height =“match_parent”.我在StackOverflow上找到了这个解决方案,我希望这也能解决我的问题.但这根本没有帮助我.

我有activity_game.xml.在那里,我有一个占位符,用于显示当前显示的片段.内容如下:

<?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>

这是捕获的屏幕来显示问题.

《android – 片段内容被切断》

如您所见,最后两个按钮正在切割.我想避免这种情况,而是让用户向下滚动.我处于一种死亡状态,我将不胜感激.我希望我设法解释这个问题,以便理解.

最佳答案 不使用ScrollView,您可以为ListView设置权重.尝试此解决方案:

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