【问题标题】:Android app not showing complete Samsung S3 miniAndroid 应用程序未显示完整的三星 S3 mini
【发布时间】:2016-01-03 01:13:02
【问题描述】:

我是 android 新手,正在开发我的第一个应用程序,它来自一个在线课程项目。事实是,在 Android Studio 上,该应用程序运行良好,但我构建了 apk 文件以在我的手机(Samsung Galaxy s3 mini)上对其进行测试。在设备上,应用程序未显示完整,因为它缺少编辑文本和布局底部的按钮。我附上了两个屏幕截图,第一个是在模拟器上运行的应用程序,另一个是在我的智能手机上运行的应用程序。

在模拟器中运行的应用程序:

在智能手机上运行的应用程序:

布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.linfosoft.hangdroid.GameActivity"
tools:showIn="@layout/activity_game">

<ImageView
android:layout_width="wrap_content"
android:layout_height="350dp"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/hangdroid_0"
android:layout_marginTop="20dp" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:background="@drawable/gradient_background"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:id="@+id/layoutAddLetter"
android:layout_marginTop="90dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Ingresa letra"
android:id="@+id/textView2"
android:layout_gravity="center_vertical"
android:layout_marginLeft="40dp" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:maxLength="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Revisar"
android:id="@+id/button2"
android:onClick="introduceLetter" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"
android:layout_marginTop="20dp"
android:id="@+id/layoutLetters">

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView7"
android:layout_marginTop="150dp"
android:layout_marginLeft="20dp"
android:textColor="@color/red" />


</RelativeLayout>

【问题讨论】:

  • 你有设备特定的布局吗?
  • 发布您的布局文件。
  • 更新帖子并包含布局代码。

标签: android android-studio apk


【解决方案1】:

将您的 xml 代码放入 ScrollView:

<ScrollView
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" >


    your xml

</ScrollView>

或在布局中增加权重:

<LinearLayout
      android:orientation="horizontal"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1">

</LinearLayout>

【讨论】:

  • 我会尝试第二个,因为我不希望用户在播放时必须上下滚动。 :)
【解决方案2】:

你的刽子手图片真的很高,因为它的值为 350dp

请检查此代码:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="10dp"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 tools:context="com.linfosoft.hangdroid.GameActivity"
 tools:showIn="@layout/activity_game">

 <RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<ImageView
 android:layout_width="wrap_content"
 android:layout_height="350dp"
 android:id="@+id/imageView"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:src="@drawable/hangdroid_0"
 android:layout_marginTop="20dp" />

<LinearLayout
 android:orientation="horizontal"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:baselineAligned="false"
 android:background="@drawable/gradient_background"
 android:layout_below="@+id/imageView"
 android:layout_centerHorizontal="true"
 android:id="@+id/layoutAddLetter"
 android:layout_marginTop="90dp">

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:text="Ingresa letra"
 android:id="@+id/textView2"
 android:layout_gravity="center_vertical"
 android:layout_marginLeft="40dp" />

 <EditText
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/editText"
 android:layout_marginLeft="20dp"
 android:layout_marginRight="20dp"
 android:maxLength="1" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Revisar"
 android:id="@+id/button2"
 android:onClick="introduceLetter" />
 </LinearLayout>

 <LinearLayout
 android:orientation="horizontal"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/imageView"
 android:layout_centerHorizontal="true"
 android:layout_alignParentBottom="false"
 android:layout_alignParentTop="false"
 android:layout_marginTop="20dp"
 android:id="@+id/layoutLetters">

 </LinearLayout>

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:id="@+id/textView7"
 android:layout_marginTop="150dp"
 android:layout_marginLeft="20dp"
 android:textColor="@color/red" />

 </RelativeLayout>
 <ScrollView>

如您所见,我使用了ScrollView,但只有当设备没有足够的空间容纳屏幕上的所有内容时,才会启用滚动视图。

在另一种情况下,它就像任何其他静态布局一样。

这并不意味着你会在每台设备上滚动它,否则你的游戏就会不那么吸引人 ;-)

另外你可以把你的图片高度改成wrap_content,但是我想作者如果这个教程是按值来做这个高度的,因为现实中的图片比有高度的要大得多的350dp

【讨论】:

  • 谢谢。我会这样做的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 2016-12-07
相关资源
最近更新 更多