我怎样才能有android“规模”我的申请?

发布于 10-31 05:33 字数 1223 浏览 6 评论 0原文

我正在创建我的第一个 Android 应用程序,这让我发疯。

我的应用程序适用于 Android 智能手机,我只需要一种特定的布局设计。我不需要更改每个设备的布局设计。我想做的就是调整布局大小以支持所有不同的屏幕尺寸和分辨率。我已经尝试了很多事情,但似乎无法做到正确。

例如: 我的页面上有几个按钮,这些按钮需要位于作为背景的图像上的特定点。即使设备的屏幕尺寸增加或屏幕分辨率增加,这些按钮仍需要位于图像上的同一点。

只是有关我的应用程序的一些信息:

-我的所有按钮位置都在 DIP 中(我尝试的解决方案之一让我这样做) -我的布局 XML 文件位于名为“layout”的文件夹中

任何帮助将不胜感激

这是我的布局之一的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mybackground"

>
<Button  
android:layout_width="115dip" 
android:layout_marginTop="450dip" 
android:layout_marginLeft="105dip" 
android:layout_height="50dip" 
android:id="@+id/button01"

>
</Button>

<Button  
android:layout_width="70dip" 
android:layout_marginTop="460dip" 
android:layout_marginLeft="250dip" 
android:layout_height="40dip" 
android:id="@+id/button03"

>
</Button>




</RelativeLayout>

上面的代码是我的布局之一。此布局有两个按钮,需要位于相对于背景“mybackground”的同一位置。这些按钮应用了透明属性,因此图像上的元素就是“按钮”。这适用于我的 Droid2,但当应用于更大或更密集的屏幕时,按钮不再位于相对于图像的正确位置。

I am creating my first android application and this has been driving me insane.

My application is for the android smartphones, and I only need one specific design for my layout. I do not need to change the design of the layout for each device. All I want to do is resize the layout to support all the different screen sizes and resolutions. I have tried multiple things and can't seem to get it right.

For Example:
I have several buttons on my pages, and the buttons need to be at a specific point on the image that I have as the background. These buttons need to still be at the same point on the image even if the device's screen size was increased or the screen resolution was increased.

Just some info about my application:

-all my button locations are in DIP (one of the solutions that I tried had me do this)
-my layout XML files are in a folder titled "layout"

Any help will be greatly appreciated

Here is the code for one of my layouts:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mybackground"

>
<Button  
android:layout_width="115dip" 
android:layout_marginTop="450dip" 
android:layout_marginLeft="105dip" 
android:layout_height="50dip" 
android:id="@+id/button01"

>
</Button>

<Button  
android:layout_width="70dip" 
android:layout_marginTop="460dip" 
android:layout_marginLeft="250dip" 
android:layout_height="40dip" 
android:id="@+id/button03"

>
</Button>




</RelativeLayout>

The code above is one of my layouts. This layout has two buttons that need to be in the same location in relation to the background "mybackground". These buttons have the transparent attribute applied to them so that elements on the image are the "buttons". This works on my Droid2, but then when applied to a screen bigger or more dense, the buttons are no longer in the correct positions in relation to the image.

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

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

发布评论

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

评论(3

夜灵血窟げ2024-11-07 05:33:55

adamp 在对 Rollin_s 问题的评论中所说的是:您需要将按钮放在背景上特定位置的原因是什么?例如,如果该点是需要对齐的另一个图像(例如),请将该图像设为自己的 ImageView,并将按钮与relativelayout 参数对齐。也许如果您提供屏幕截图,有人可以为您提供更好的示例。此外,GridView 和 TableLayout 是对齐布局组件以适应不同屏幕尺寸的好对象。

What adamp is saying in his comment on Rollin_s's question is: What is the reason for you needing the buttons to be over a specific spot on the background? If that spot is another image (for example) that needs to be aligned, make that image its own ImageView and align the button with RelativeLayout parameters. Maybe if you included a screenshot, someone could give you a better example of what to do. Also, GridView and TableLayout are good objects for aligning layout components to fit different screen sizes.

旧时光的容颜2024-11-07 05:33:55

听起来有点时髦,但如果您需要处理的只是等效 iPhone UI 的扁平图像,并且您需要添加的唯一 UI 元素是其顶部的按钮,那么我可能会尝试以下替代方案来代替繁琐的工作尝试让透明按钮对齐:

  • 确定按钮位置相对于正常/未缩放图像的位置,在您选择的某些数据结构中记录顶部、左侧、底部、右侧值
  • 将图像放置在设置为缩放的 ImageView 中使用 FitXY
  • 通过检查 ImageViews H & 来计算 Android 应用于图像的缩放比例。 W 与您的原生图像 H & 进行比较我们
  • 做了一些数学运算来缩放原始值的顶部、左侧、底部和右侧值
  • 然后在图像视图的 onClick 处理程序中,您应该能够测试触摸的坐标是否在您缩放的边界内现在已经有了。

可能会比摆弄布局更准确,更容易维护,并且更少麻烦。

当然,更正确的解决方案是获取用于执行 iPhone 应用程序的实际单个图形元素,并在 Android 中重新实现 UI。

祝你好运。

Sounds a bit funky but if all youve got to work with is a flattened image of the equivalent iPhone UI and the only UI elements you need to add are buttons over top of it, I might be tempted to try the following alternative to the tedious work of trying to get the transparent buttons to align:

  • Determine where your button locations are relative to your normal/unscaled image, record the top, left, bottom, right values in some data structure of your choosing
  • Place your image in an ImageView set to scale using FitXY
  • calculate the scaling that android has applied to your image by examining the ImageViews H & W and comparing to what your native image H & W were
  • do some math to scale the top,left,bottom, and right values from your original values
  • Then in an onClick handler for your image view you should be able to test to see if the touched coordinates are within any of the scaled boundaries you've now got.

Probably would be more accurate, easier to maintain, and less hassle than fiddling with the layout stuff.

Of course, the more correct solution would be to get the actual individual graphic elements used to do the iPhone app and re-implement the UI in android proper.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文