如何在android中以编程方式获取屏幕密度?
我的意思是:如何找到当前设备的屏幕dpi?
我正在开发Android v2.2应用程序.
我有一个片段.
在onCreateView(...)我的片段类的回调中,我将布局扩展到片段,如下所示:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login, null);
return view;
}
Run Code Online (Sandbox Code Playgroud)
上面膨胀的布局文件是(login.xml):
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Username" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Username" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想设置一个paddingTop上面的<LinearLayout>元素,我想在Java代码中执行它而不是在xml中执行它.
如何设置paddingTop到<LinearLayout>我的片段Java类代码?
android padding android-widget android-emulator android-layout
我使用表格布局将数据显示为表格,但我想要一个包含用户定义列和带边框的行的表格.建议?
可能重复:
android中px,dp,dip和sp的差异
我是Android新手,我正在尝试本教程
在该教程中,他们使用单位"sp"表示textSize属性,使用"dp"表示其他属性.
请告诉我sp与sp不同?
我有一个背景,我需要适合所有屏幕尺寸.我有三个文件夹,hdpi,ldpi并mdpi为可绘制,但在模拟器有什么分辨率没有任何referense hdpi是什么mdpi和ldpi有.
我知道DP,SP和PX之间的区别.在搜索了这个主题后,我发现没有什么能让我完全满意.也许这篇文章是重复的,但我仍然想知道从DP到PX,DP到SP,从SP到PX,从PX到SP,从SP到DP,从DP到SP的转换公式是什么?我知道一些代码可以做到这一点,但它们并不完美.
大家好我刚刚在LinearLayout中实现了ListView,但我需要定义LinearLayout的高度(它必须是屏幕高度的50%).
<LinearLayout
android:id="@+id/widget34"
android:layout_width="300px"
android:layout_height="235px"
android:orientation="vertical"
android:layout_below="@+id/tv_scanning_for"
android:layout_centerHorizontal="true">
<ListView
android:id="@+id/lv_events"
android:textSize="18sp"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_scanning_for"
android:layout_centerHorizontal="true">
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这有可能吗?
我为一个按钮和一个EditText做了类似的事情,但似乎不适用于Layouts.
这是我的代码:
//capture the size of the devices screen
Display display = getWindowManager().getDefaultDisplay();
double width = display.getWidth();
//my EditText will be smaller than full screen (80%)
double doubleSize = (width/5)*4;
int editTextSize = (int) doubleSize;
//define the EditText
userName = (EditText) this.findViewById(R.id.userName);
password = (EditText) this.findViewById(R.id.password);
//set the size
userName.setWidth(editTextSize);
password.setWidth(editTextSize);
Run Code Online (Sandbox Code Playgroud)
谢谢!:)
size android android-layout android-linearlayout android-layout-weight
我是一名视觉设计师,从事Android设计工作,我正在尝试为我们的工程师指定我的PSD文件.我似乎无法找到任何关于在任何Android文档中将点大小转换为SP的文档.(只是SP应该用于类型).
我一直在尝试使用本教程在Android中创建一个自定义按钮 - http://www.gersic.com/blog.php?id=56
它运作良好,但没有说明如何更改字体大小或权重.有任何想法吗?
这里还有另一个问题,唯一的答案是使用html样式但是你不能在不使用css(或不推荐的字体标签)的情况下更改html中的字体大小.必须有更好的方法来设置按钮上使用的字体的像素大小?
android ×10
size ×2
dimensions ×1
dpi ×1
hdpi ×1
padding ×1
pixel ×1
psd ×1
screen ×1
tablelayout ×1