【问题标题】:Android View Clipped below certain pointAndroid视图剪辑低于某个点
【发布时间】:2011-10-24 17:42:17
【问题描述】:

我正在开发一个 Android 应用(见屏幕截图)。

我的布局在图形编辑器中看起来不错。但是,当应用程序在模拟器和安卓手机上运行时,屏幕底部的 1/4 会从视图中被剪掉。该应用程序有几个活动,而且问题似乎对所有人都很普遍。

这是我正在使用的布局。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" android:clipChildren="false" android:clipToPadding="false" android:layout_height="fill_parent">
    <ImageView android:layout_height="wrap_content" android:src="@drawable/simpsonstextblack" android:layout_width="fill_parent" android:id="@+id/TitleImage" android:paddingBottom="25dp"></ImageView>
    <RelativeLayout android:layout_below="@+id/TitleImage" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/RelativeLayout1" android:padding="5dp">
        <Button android:text="Take the Simpsons Challenge" android:gravity="center" android:clickable="true" android:id="@+id/ChallengeButton" android:layout_width="fill_parent" android:textSize="20dp" android:background="@drawable/buttonbackgroundblue" android:layout_height="50dp"></Button>
        <TextView android:layout_width="fill_parent" android:layout_below="@+id/ChallengeButton" android:layout_alignLeft="@+id/ChallengeButton" android:id="@+id/spacer1" android:layout_height="6dp"></TextView>
        <Button android:layout_width="fill_parent" android:text="Free Play" android:clickable="true" android:id="@+id/FreePlayButton" android:layout_height="50dp" android:textSize="20dp" android:background="@drawable/buttonbackgroundblue" android:layout_below="@+id/spacer1"></Button>
        <TextView android:layout_width="fill_parent" android:id="@+id/spacer2" android:layout_below="@+id/FreePlayButton" android:layout_alignLeft="@+id/FreePlayButton" android:layout_height="6dp"></TextView>
        <Button android:layout_height="50dp" android:textSize="20dp" android:id="@+id/HighScoreButton" android:background="@drawable/buttonbackgroundblue" android:layout_width="fill_parent" android:text="High Scores" android:layout_below="@+id/spacer2"></Button>
        <TextView android:layout_width="fill_parent" android:id="@+id/spacer3" android:layout_below="@+id/HighScoreButton" android:layout_alignLeft="@+id/HighScoreButton" android:layout_height="6dp"></TextView>
        <Button android:layout_height="50dp" android:textSize="20dp" android:id="@+id/HelpButton" android:background="@drawable/buttonbackgroundblue" android:layout_width="fill_parent" android:text="Help" android:layout_below="@+id/spacer3"></Button>
    </RelativeLayout>
    <RelativeLayout android:layout_below="@+id/RelativeLayout1" android:layout_width="fill_parent" android:id="@+id/RelativeLayout2" android:clipChildren="false" android:clipToPadding="false" android:layout_height="fill_parent">
        <TextView android:id="@+id/spacer1" android:layout_width="fill_parent" android:layout_height="30dp"></TextView>
        <TextView android:layout_below="@+id/spacer1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/QuoteText" android:text='"A woman is a lot like a refrigerator. Six feet tall, 300 pounds…it makes ice. Heres some extra filler text just to demonstrate to you that if you add enough text it will most likely get clipped at some random point in the screen seemingly for no reason."'></TextView>
    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

  • 我无法在我的设备上重现此问题。当您在设备上运行时,它会显示与模拟器相同的内容吗?
  • 是的,截图来自模拟器本身。尝试在底部的文本视图中添加几行文本,看看它们是否被剪辑。
  • 我的意思是它可能在物理设备上正常工作而不是在模拟器中,尽管它应该在模拟器中工作。只是想排除这种可能性。我已经添加了足够多的文本行,让它滚动到屏幕底部,但它只会在我的设备上的屏幕边缘剪辑它。
  • 有趣。我确实在朋友的手机上尝试了旧版本的布局,并且遇到了与模拟器相同的问题,但也许一些小的修补程序修复了它。我试试看。
  • 手机上仍然没有变化。问题似乎是应用程序范围内的,并且显然因手机而异。是否有任何应用程序范围的变量可以控制这一点?我是开发新手,所以我完全有可能犯了一个非常愚蠢的错误。

标签: android layout graphics view clipped


【解决方案1】:

我的猜测是您的应用程序在兼容模式下运行。尝试在清单中设置以下内容:

<supports-screens android:smallScreens="true"
    android:normalScreens="true" 
    android:largeScreens="true"
    android:anyDensity="true" />

如果是问题,您可以在此处阅读更多信息:http://developer.android.com/guide/topics/manifest/supports-screens-element.html。 简而言之,android:largeScreens 默认值因版本而异 :)

【讨论】:

    【解决方案2】:

    问题是您的最后一个 TextView (@+id/QuoteText) 设置为 android:visibility="invisible"。这意味着内容是不可见的,但它仍然占用空间。你想改用android:visibility="gone"

    对于之前在我的手机上无法正常工作的说法,我深表歉意。因为文本没有到达我设备上的屏幕底部,所以我在顶部的 ImageView 中添加了空间,但是这将 TextView 推到了屏幕之外,所以它似乎对我有用。希望这会有所帮助!

    编辑:

    这也不是问题。我认为问题在于您的底部 RelativeLayout 定义为

    <RelativeLayout
        android:layout_width="fill_parent"
        android:id="@+id/RelativeLayout1"
        android:layout_height="200dp">
    

    这给底部面板一个固定的高度。当我将android:layout_height="200dp" 更改为android:layout_height="fill_parent" 时,剪裁问题就消失了。也许您的其他活动也有同样的问题?

    我不明白为什么您的布局不起作用,但我确实认为通过使用 LinearLayouts 而不是 RelativeLayouts,您可以更轻松、更有效地实现相同的目标。也许它会一路解决你的问题。我认为最好使用填充,而不是使用间隔视图。这就是我的意思:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/TitleImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:src="@drawable/simpsonstextblack" >
        </ImageView>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TitleImage"
            android:orientation="vertical"
            android:padding="5dp" >
    
            <Button
                android:id="@+id/ChallengeButton"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:clickable="true"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:text="Take the Simpsons Challenge"
                android:textSize="20dp" >
            </Button>
    
            <Button
                android:id="@+id/FreePlayButton"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:clickable="true"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:text="Free Play"
                android:textSize="20dp" >
            </Button>
    
            <Button
                android:id="@+id/HighScoreButton"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:text="High Scores"
                android:textSize="20dp" >
            </Button>
    
            <Button
                android:id="@+id/HelpButton"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:text="Help"
                android:textSize="20dp" >
            </Button>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
    
            <TextView
                android:id="@+id/QuoteText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingTop="30dp"
                android:text="&quot;A woman is a lot like a refrigerator. Six feet tall, 300 pounds…it makes ice. Heres some extra filler text just to demonstrate to you that if you add enough text it will most likely get clipped at some random point in the screen seemingly for no reason. &quot;"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 我知道那个 textview 是不可见的。我应该把它拿出来,但这不是问题(如果我将它设置为消失,屏幕仍然会在屏幕下方剪切 75% 并遮挡引用文本。同样,这个问题在应用程序中的所有活动中都很普遍,所以问题可能不在于任何单独的视图元素。
    • 你是对的,这不是问题所在。我已经编辑了我的答案,看看是否有帮助。
    • 没有效果,还是被剪掉了。
    • 您能否将您的 XML 布局更新为您当前的布局?另外,您用于 ImageButton 的图像的高度是多少?
    • 布局已更新。按钮图像是 PNG 638 x 93。问题是否与删除标题栏/显示全屏有关?
    猜你喜欢
    • 2011-07-31
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2012-08-17
    相关资源
    最近更新 更多