[英]why my android app works fine in emulator but display is totally terrible in real device/
i made an android app and it looks good in different screen sizes in emulator but when i run it in a real device, it runs but the display is totally terrible.我制作了一个 android 应用程序,它在模拟器中的不同屏幕尺寸下看起来不错,但是当我在真实设备上运行它时,它运行但显示非常糟糕。 i am using linear layout in my XML and my code for it is below.
我在我的 XML 中使用线性布局,我的代码如下。 i have a table with some rows which contains data.
我有一个表,其中包含一些包含数据的行。 it fits good with emulator but with real device the apps runs but display is totally bad.
它非常适合模拟器,但对于真实设备,应用程序可以运行,但显示效果很差。 do not get it why runs good in emulator and bad in real device although its same resolution!
不明白为什么在模拟器中运行良好而在真实设备中运行不佳,尽管其分辨率相同!
https://imgur.com/meYkj5T on emulator https://imgur.com/meYkj5T在模拟器上
https://imgur.com/cfv8PlG running on emulator https://imgur.com/cfv8PlG在模拟器上运行
https://imgur.com/oaGVt7J running on real device https://imgur.com/oaGVt7J在真实设备上运行
https://imgur.com/8alDEZC linearlayout width and height is match parent https://imgur.com/8alDEZC 线性布局宽度和高度与父级匹配
<?XML version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:fillViewport="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal|vertical">
<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:scrollbars="horizontal|vertical">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:shrinkColumns="*"
android:stretchColumns="*"
android:weightSum="10">
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:weightSum="5"
android:layout_margin="1dp"
android:background="@drawable/border"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_margin="1dp"
android:gravity="center"
android:text=" IP "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:weightSum="10"
app:autoSizeTextType="uniform" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_margin="1dp"
android:gravity="center"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:weightSum="10"
app:autoSizeTextType="uniform" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_margin="1dp"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:weightSum="10"
app:autoSizeTextType="uniform" />
</TableRow>
<TableRow
android:id="@+id/tableRow0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:gravity="center"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:gravity="center"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold"
app:autoSizeTextType="uniform" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:gravity="center"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="1dp"
android:gravity="center"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold"
app:autoSizeTextType="uniform" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:gravity="center"
android:text=" "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14dp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
You have added weightsum for you TableRow.您已经为您的 TableRow 添加了 weightsum。 You need to make changes as below -
您需要进行如下更改 -
Replace weightsum for first TableRow to 3将第一个 TableRow 的 weightsum 替换为 3
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:weightSum="3"
android:layout_margin="1dp"
android:background="@drawable/border">
Also remove below line from Child TextViews同时从 Child TextViews 中删除下面的行
android:weightSum="10"
Add below lines to Child TextViews将以下行添加到子 TextViews
android:layout_width="0dp"
android:layout_weight="1"
I hope it will work for you.我希望它对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.