【发布时间】:2015-02-21 14:17:44
【问题描述】:
我通过在线性布局中为视图分配权重来为视图分配空间。可以看出textView的高度是(屏幕高度*5)/12。
布局的xml文件如下-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.greenloop.numbers.Counting_Ten"
android:orientation="vertical"
tools:ignore="MergeRootFrame"
android:background="#FFA500">
<RelativeLayout android:id="@+id/rel_number_fragment"
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#800000">
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onClick"
android:background="#800080"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/image_frame"
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="0dp">
</FrameLayout>
<fragment android:name="com.example.Navigation_Buttons"
android:id="@+id/button_fragment"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
我已将java文件中的textsize设置为
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screen_height = displaymetrics.heightPixels;
text_size = (int) (((screen_height*5.0)/12.0));
textview.setTextSize(TypedValue.COMPLEX_UNIT_PX,text_size);
现在的问题 -:我已经在手机上运行了这个,一切都很好。文本大小与文本视图一样大。但是当我在 10 英寸平板电脑和 Nexus 5 的 GENYMOTION 模拟器上运行相同的东西时,Logcat 显示 - 字体太大,无法放入缓存。宽度、高度 = 175、527。我无法弄清楚这一点。可以是因为字体风格不同?
【问题讨论】:
-
您可以使用
sdk\tools下的monitor.bat来检查视图的层次结构是否正确。 -
会不会是字体样式的不同?
-
也许,你可以给个更小的尺寸看看它是否会显示
-
如果我把它设置得太低,比如 1/12 而不是 5/12 * screen_height 它会显示出来。另外,我通过 java 设置字体样式进行了检查,但结果仍然相同 - 在手机上工作但在模拟器上没有
标签: android layout emulation text-size