相关疑难解决方法(0)

在android中以编程方式获取屏幕密度?

如何在android中以编程方式获取屏幕密度?

我的意思是:如何找到当前设备的屏幕dpi?

android dpi screen-density

505
推荐指数
15
解决办法
28万
查看次数

以编程方式在视图上添加填充

我正在开发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

221
推荐指数
9
解决办法
23万
查看次数

如何在Android中创建带边框的表格?

我使用表格布局将数据显示为表格,但我想要一个包含用户定义列和带边框的行的表格.建议?

android tablelayout

178
推荐指数
11
解决办法
34万
查看次数

我们为什么要在Android中使用sp作为字体大小?

可能重复:
android中px,dp,dip和sp的差异

我是Android新手,我正在尝试本教程

在该教程中,他们使用单位"sp"表示textSize属性,使用"dp"表示其他属性.

请告诉我sp与sp不同?

user-interface android

134
推荐指数
2
解决办法
6万
查看次数

Android屏幕尺寸HDPI,LDPI,MDPI

我有一个背景,我需要适合所有屏幕尺寸.我有三个文件夹,hdpi,ldpimdpi为可绘制,但在模拟器有什么分辨率没有任何referense hdpi是什么mdpildpi有.

size android screen hdpi

117
推荐指数
4
解决办法
42万
查看次数

dp与dip相同吗?

可能重复:
android中px,dp,dip和sp的差异

我已经找到了几个主题.但没有人真的回答我的问题.

Dp和dip在android中.有什么不同?这是一回事吗?

android dimensions

93
推荐指数
2
解决办法
4万
查看次数

如何将DP,PX,SP相互转换,尤其是DP和SP?

我知道DP,SPPX之间的区别.在搜索了这个主题后,我发现没有什么能让我完全满意.也许这篇文章是重复的,但我仍然想知道从DPPX,DPSP,从SPPX,从PXSP,从SPDP,从DPSP的转换公式是什么?我知道一些代码可以做到这一点,但它们并不完美.

android pixel density-independent-pixel

53
推荐指数
4
解决办法
4万
查看次数

android:layout_height屏幕大小的50%

大家好我刚刚在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

45
推荐指数
3
解决办法
13万
查看次数

如何将pt转换为sp?

我是一名视觉设计师,从事Android设计工作,我正在尝试为我们的工程师指定我的PSD文件.我似乎无法找到任何关于在任何Android文档中将点大小转换为SP的文档.(只是SP应该用于类型).

android psd units-of-measurement

40
推荐指数
3
解决办法
6万
查看次数

Android按钮字体大小

我一直在尝试使用本教程在Android中创建一个自定义按钮 - http://www.gersic.com/blog.php?id=56

它运作良好,但没有说明如何更改字体大小或权重.有任何想法吗?

这里还有另一个问题,唯一的答案是使用html样式但是你不能在不使用css(或不推荐的字体标签)的情况下更改html中的字体大小.必须有更好的方法来设置按钮上使用的字体的像素大小?

android

37
推荐指数
3
解决办法
11万
查看次数