Bha*_*ani 78 android screen-resolution android-custom-view android-xml android-drawable
编辑问题:
移动分辨率:
我想设计不同的屏幕dpi,如下面的分辨率.
小320x480,
480×800,
540x960,
720x1280(三星S3),
1080×1920(S4,Nexus5,纳克斯5X,摩托G4),
2560 X 1440(的Nexus 6,纳克斯6P,三星边缘)
平板分辨率:
480×800(Micromax的),
600x1024(三星tab2),
800x1280(nexus 7),
1200x1920(新nexus 7),
2048x1536(nexus 9)
我想根据设备显示分辨率使用不同的字体大小.
Q1)best解决这个问题的方法是什么problem?
Q2)什么是抛出编码或XML的最佳选择?
Q3)哪个drawable文件夹代表哪个设备分辨率?
Q4)应用程序启动器图标大小为不同的分辨率?
Bha*_*ani 186
不同分辨率的应用启动器图标大小(以像素为单位)
移动分辨率
如果您希望具有特定于平板电脑的布局,请使用以下文件夹:
layout-large-mdpi (1024x600)
layout-large-tvdpi (800x1280)
layout-large-xhdpi (1200x1920)
layout-xlarge-mdpi (1280x800)
layout-xlarge-xhdpi (2560x1600)
Run Code Online (Sandbox Code Playgroud)
移动
res/drawable (default)
res/drawable-ldpi/ (240x320 and nearer resolution)
res/drawable-mdpi/ (320x480 and nearer resolution)
res/drawable-hdpi/ (480x800, 540x960 and nearer resolution)
res/drawable-xhdpi/ (720x1280 - Samsung S3, Micromax Canvas HD etc)
res/drawable-xxhdpi/ (1080x1920 - Samsung S4, HTC one, Nexus 5, etc)
res/drawable-xxxhdpi/ (1440X2560 - Nexus 6,Samsung S6edge).
Run Code Online (Sandbox Code Playgroud)平板电脑分辨

注意:在处理时总是尝试使用SP
textSize,例如textsize=12sp
使用预定义textAppearance:
它将根据设备密度自动设置文本大小.
<TextView android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" />
Run Code Online (Sandbox Code Playgroud)
样品用法:
<TextView
style="@android:style/TextAppearance.Small"
android:text="Sample Text - Small" />
<TextView
style="@android:style/TextAppearance.Medium"
android:text="Sample Text - Medium" />
<TextView
style="@android:style/TextAppearance.Large"
android:text="Sample Text - Large" />
Run Code Online (Sandbox Code Playgroud)使用dimension.xml每个设备:
从Google IO Pdf,我们看到以下结构:
移动:
res/values/dimens.xml(default)
res/values-ldpi/dimens.xml (240x320 and nearer resolution)
res/values-mdpi/dimens.xml (320x480 and nearer resolution)
res/values-hdpi/dimens.xml (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml (720x1280 - Samsung S3, Micromax Canvas HD, etc)
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
Run Code Online (Sandbox Code Playgroud)
res/values-xxxhdpi/dimens.xml(1440X2560 - Nexus 6,Samsung S6edge).
片剂:
对于平板电脑,你可以用更具体的文件夹一样values-xlarge,values-large.
res/values-large/dimens.xml (480x800)
res/values-large-mdpi/dimens.xml (600x1024)
Run Code Online (Sandbox Code Playgroud)
要么
res/values-sw600dp/dimens.xml (600x1024)
res/values-sw720dp/dimens.xml (800x1280)
res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
res/values-large-xhdpi/dimens.xml (1200x1920 - Nexus 7"(latest))
Run Code Online (Sandbox Code Playgroud)了解更多信息:
请参阅支持多个屏幕.
有关设计设备密度,请参阅Google IO Pdf的第#77页.在那里,您将找到处理不同设备的方法.
dimens.xml- 让您的应用程序为Nexus 6和Nexus 9做好准备.
与密度无关的像素相当于160 dpi屏幕上的一个物理像素,这是系统为"中等"密度屏幕假定的基线密度.在运行时,系统根据所使用屏幕的实际密度,根据需要透明地处理dp单元的任何缩放.将dp单位转换为屏幕像素非常简单:
px = dp * (dpi / 160).例如,在240 dpi屏幕上,1 dp等于1.5个物理像素.在定义应用程序的UI时,应始终使用dp单位,以确保在具有不同密度的屏幕上正确显示UI.
Pan*_*rma 27
首先,为不同的屏幕创建不同的值文件夹.根据res->values->dimens.xml文件中的屏幕放置大小,并使用调用简单的字体大小"@dimen/text_size".
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml
//for small
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">15sp</dimen>
</resources>
//for normal
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">20sp</dimen>
</resources>
//for large
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">30sp</dimen>
</resources>
//for xlarge
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">40sp</dimen>
</resources>
Run Code Online (Sandbox Code Playgroud)
并检索TextView下面给出的字体大小.
<TextView
android:id="@+id/lblHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size"
android:textStyle="bold"
android:typeface="serif" />
Run Code Online (Sandbox Code Playgroud)
基本上你需要创建一个像这样的文本样式:
<style name="CodeFont">
<item name="android:textSize">30sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在http://developer.android.com/guide/topics/ui/themes.html上阅读更多相关信息
并使用Android支持不同的屏幕指南为右侧res文件夹中的不同屏幕创建所需的不同大小,如:http://developer.android.com/guide/practices/screens_support.html
旁注:我真的不明白你想要在什么情况下这样做,使用SP单位的字体大小会缩放字体在不同的手机上看起来或多或少相同的大小.
为了避免不同屏幕分辨率和不同密度的问题,我根据屏幕的百分比宽度和高度来确定尺寸和位置.如果根据屏幕的百分比宽度或高度调整文本大小,则字体在所有设备和所有分辨率上的大小都将正确.要根据空间的宽度和高度获得正确的字体大小,只需使用此功能:
private float SetTextSize(String text, int width, int height)
{
Paint paint = new Paint();
float textWidth = paint.measureText(text);
float textSize = (int) ((width / textWidth) * paint.getTextSize());
paint.setTextSize(textSize);
textWidth = paint.measureText(text);
textSize = (int) ((width / textWidth) * paint.getTextSize());
// Re-measure with font size near our desired result
paint.setTextSize(textSize);
// Check height constraints
FontMetricsInt metrics = paint.getFontMetricsInt();
float textHeight = metrics.descent - metrics.ascent;
if (textHeight > height)
{
textSize = (int) (textSize * (height / textHeight));
paint.setTextSize(textSize);
}
return textSize;
}
Run Code Online (Sandbox Code Playgroud)
这是获取屏幕宽度和高度的代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
{
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
screenWidth = size.x;
screenHeight = size.y;
}
else
{
Display display = getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
}
Run Code Online (Sandbox Code Playgroud)
要获得所需的字体大小,只需根据屏幕宽度和屏幕高度组成一个区域并调整它直到字体大小正确.一旦你看起来正确,它应该在所有设备上看起来正确.
float textSize = SetTextSize("text", (int) (screenWidth * 0.1), (int) (screenHeight * 0.15));
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助你
首先,您的应用程序设计为一个分辨率。
示例:假设您的手机分辨率为380*480
mobile screen width:380
textView size is 80dp
Assume : if width is 380dp then 100 % then
textview width 80dp then how many %(per).
ower answer is: 25 %
Run Code Online (Sandbox Code Playgroud)
使用 Belove 公式以编程方式查找屏幕尺寸
DisplayMetric displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
ScreenHeight = displaymetrics.heightPixels;
ScreenWidth = displaymetrics.widthPixels;
txt_height = (int)((ScreenHeight*14.58)/100);
txt_width = (int)((ScreenWidth*37.5)/100);
LinearLayout.LayoutParams normal_param = new LinearLayout.LayoutParams(txt_height ,txt_width );
txt_Name.setLayoutParams(normal_param);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89104 次 |
| 最近记录: |