Android布局,固定尺寸为cm /英寸

发布于 2025-02-12 08:18:22 字数 116 浏览 1 评论 0原文

什么可以用来确保在Android Studio开发时,容器始终在CM /英寸中始终相同?

我需要将其集中在屏幕中间,无论手机/平板电脑在哪种上运行,以使中间的元素是相同的高度/长度。

谢谢!

What can be used to make sure the container will always be the same size in cm / inches when developing in android studio?

I need it to be centered in the middle of the screen regardless of what phone/tablet is running on so that the element in the middle is same height/length.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2025-02-19 08:18:22

使用** DP-密度独立的像素**给它进行修复和高度,在不同的屏幕上将具有相同的尺寸。
屏幕中间,取决于您的父viewgroup,例如线性布局,relativelayout,CondertantLayout等

将其放在

android:gravity =线性布局中的“中心”将它们放在中间

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<View
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:background="#000000"
    />

Giving it a fix with and height using ** dp - Density-independent Pixels** will have the same size on different screen.
having it in the middle of the screen depend on your parent ViewGroup like Linear layout, relativeLayout, ConstrantLayout etc.

using

android:gravity="center" in linear layout put them in the middle

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<View
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:background="#000000"
    />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文