2

在我的应用程序的顶部,我有一个应该显示在中间的标题,右边是一个按钮。由于 textViews 的长度在我的控制范围之内,有时我的标题会因为内容的长度过长而穿过按钮。

遵循之后,我以某种方式倾向于解决问题。我的设备是 HTC 的愿望。不幸的是,如果我使用 Galaxy SIII 进行检查,它并不能解决问题。

我想知道如何根据不同密度的不同设备来管理它。

我在相对布局中的控件

4

4 回答 4

1

您还可以通过以下方式检查设备屏幕密度 -

    WindowManager wm = (WindowManager) _context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();

并且可以相应地管理您的应用程序需要什么..

于 2012-12-12T05:51:14.890 回答
0

只需在您的 xml 中使用 weightsum 并将所有视图的宽度设置为填充父级.....这会使您的 textview 自动调整大小

于 2012-12-12T05:47:54.760 回答
0

您可以根据他们的 DPI 维护布局,在 XHDPI 中复制相同的 XML 数据(因为 S3 属于 XHDPI)并测试它类似地在 HDPI 中复制 XML 数据,但请记住 layoutOut 的以下 Thing Pixel Ratio 如下

在 LDPI 中为 1:0.75 在 MDPI 中为 1:1 在 HDPI 中为 1:1.5 在 XHDPI 中为 1:2

于 2012-12-12T05:50:22.950 回答
0
Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
float density = dm.density; 
int screenWidth = display.getWidth();

使用上面的代码,您的屏幕密度将为浮动。因此您可以使用它来计算 textView 的宽度,例如:

int newWidth = (int) (density * 100);

其中 100 是基于大小的。或者你可以根据你的 screenWdith 设置一个比例。

int newWidth = screenWidth / 2;
于 2012-12-12T06:14:05.447 回答