片段内容被切断 [英] Fragment content gets cut off

查看:70
本文介绍了片段内容被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发Android游戏.我的片段中的内容有问题.内容被截断,我找不到问题.我只使用资源目录,在其中定义了不同的布局.这就是为什么我知道问题出在布局上的原因.首先,我认为这与我使用 android:layout_height ="match_parent" 的事实有关.我在StackOverflow上找到了该解决方案,希望也能解决我的问题.但这根本没有帮助我.

I am currently developing an Android game. I have a problem with my content inside a Fragment. The content gets cut off and I am not able to find the problem. I only use the resource directory, where I define the different layouts. That is why I know the problem lies in the layouts. First I thought it has something to do with the fact I used android:layout_height="match_parent". I found this solution on StackOverflow and I hoped that would also solve my problem. But this did not help me at all.

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

I have the activity_game.xml. There I have a placeholder for the current displayed Fragment. The content is the following:

<?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 本身定义了以下布局:

The Fragment itself has the following layout defined:

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

这是捕获的屏幕,用于显示问题.

And here is the captured screen to show the problem.

如您所见,最后两个按钮已被剪切.我想避免这种情况,而是允许用户向下滚动.我处于死境,我将不胜感激.我希望我能对问题做出充分的解释,以至于可以理解.

As you can see, the last two buttons are being cut. I would like to avoid that and rather allow the user to scroll down. I am in a dead situation and I would appreciate any help. And I hope I manage to explain the problem good enough to be understood.

推荐答案

无需使用 ScrollView ,就可以为 ListView 设置 weight .尝试以下解决方案:

Without using ScrollView, you can set weight for ListView. Try this solution:

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

这篇关于片段内容被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆