怎样才能在屏幕的某些位置对齐的意见,住在多个屏幕分辨率是否一致? [英] How does one align views at certain positions of the screen, staying consistent across multiple screen resolutions?

查看:316
本文介绍了怎样才能在屏幕的某些位置对齐的意见,住在多个屏幕分辨率是否一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有位对准我的按钮有问题。我想,让他们在(大约)1/3和我的屏幕的2/3日(我在下面提供的截图,以使事情更清楚一点)
我的code是以下内容:

I've got a bit of a problem aligning my buttons. I want to get them at (roughly) 1/3rd and 2/3rd of my screen (I provided a screenshot below to make things a bit more clear) My code is the following:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="@drawable/mainbg">

    <Button 
        android:text="@string/topbutton"
        android:background="@drawable/silvertablesbuttonbgkort"
        android:id="@+id/topbutton"
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center|center_vertical">
    </Button>

    <Button 
        android:text="@string/midbutton"
        android:background="@drawable/silvertablesbuttonbglang"
        android:id="@+id/midbutton"
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center|center_vertical">
   </Button>


<RelativeLayout 
    android:id="@+id/underbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button 
        android:text="@string/underbartekst"
        android:background="@drawable/silvertablesunderbar"
        android:id="@+id/underbarbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:textSize="20dp"
        android:gravity="left|center_vertical" >
    </Button>

</RelativeLayout>

我试图让它看起来像这样:(对不起,如果公布的截图实物模型是建立在这里皱了皱眉头,我想不出更好的方式来清理我尝试到做)

I'm trying to get it to look like this: (I'm sorry if posting screenshot mock-ups is frowned upon here, I just couldn't think of a better way to clear up what I'm trying to do)

看来,因为我太新在这里我不能发表图片...所以这里是一个链接的截图:的 http://i.imgur.com/l3b3z.png

It seems that I can't post images because I'm too new here... So here is a link to the screenshot: http://i.imgur.com/l3b3z.png

我最初的想法只是环绕周围的两个按钮的垂直线性布局,并把以上和空textviews两个,如果这个应用程序是为了要在一个屏幕大小运行这将实际工作之间,但我pretty肯定它会搞砸了所有手机都与其他的屏幕分辨率。我用与Android一RelativeLayout的解决了这个问题,在底部的工具栏:layout_alignParentBottom =真,但我真的不能想办法捕捉到1/3或2/3。有没有办法做到这一点,将与不同的屏幕分辨率工作?

My initial idea was just wrapping a vertical linear layout around the two buttons and putting empty textviews above and in between the two, which would actually work if this app was meant to be running on one screen size, but I'm pretty sure it'd mess up on every phone with another screen resolution. I solved this problem for the bar at the bottom by using a relativelayout with android:layout_alignParentBottom="true", but I can't really think of a way to snap to 1/3rd or 2/3rd. Is there a way to do this that will work with various screen resolutions?

编辑:
我解决我的问题!我试图将它张贴作为一个答案,但我不能,直到8小时。会做的话,但现在,我只是将它张贴作为编辑在这里:

I solved my problem! I tried to post it as an answer, but I can't until in 8 hours. Will do then, but for now, I'll just post it as an edit here:

我已经放在为0x0的一个TextView在屏幕中间,并把RelativeLayouts上的和它下面顶部,填充屏幕。然后,我把为0x0两种TextViews这些布局的中间,这些布局中,两个新RelativeLayouts。下面的一个最高的TextView,一个在上最低的。我把这些布局的中心,我的按钮。它的工作原理就像一个魅力,而且不依赖于任何东西,但code本身。这是我的code现在:

I've placed a TextView of 0x0 in the middle of the screen, and put RelativeLayouts on top of and below it, filling the screen. Then I placed two TextViews of 0x0 in the middle of those layouts, and within those layouts, two new RelativeLayouts. One below the highest TextView, one above the lowest. I placed my buttons in the center of those layouts. It works like a charm, and does not rely on anything but the code itself. This is my code now:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="@drawable/mainbg">


    <TextView 
        android:text=" "
        android:id="@+id/ankermidden"
        android:layout_centerVertical="true"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </TextView>

    <RelativeLayout
        android:id="@+id/ankerveldboven"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/ankermidden">

                <TextView 
                    android:text=" "
                    android:id="@+id/ankerboven"
                    android:layout_centerVertical="true"
                    android:layout_width="0dp"
                    android:layout_height="0dp">
                </TextView>

            <RelativeLayout
                android:id="@+id/ankerveldmidboven"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/ankerboven">

                 <Button 
                    android:text="@string/topbutton"
                    android:background="@drawable/silvertablesbuttonbgkort"
                    android:id="@+id/topbutton"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center|center_vertical">
                </Button>

            </RelativeLayout>

</RelativeLayout>


<RelativeLayout
        android:id="@+id/ankerveldonder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/ankermidden">

    <TextView 
        android:text=" "
        android:id="@+id/ankeronder"
        android:layout_centerVertical="true"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </TextView>

            <RelativeLayout
                android:id="@+id/ankerveldmidonder"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/ankeronder">      

                <Button 
                    android:text="@string/midbutton"
                    android:background="@drawable/silvertablesbuttonbglang"
                    android:id="@+id/midbutton"
                    android:layout_alignParentRight="true" 
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center|center_vertical">
                </Button>

            </RelativeLayout>       

 </RelativeLayout>

<RelativeLayout 
    android:id="@+id/underbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button 
        android:text="@string/underbartekst"
        android:background="@drawable/silvertablesunderbar"
        android:id="@+id/underbarbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:textSize="20dp"
        android:gravity="left|center_vertical" >
    </Button>

</RelativeLayout>

所以是的,这是比我想象的更容易。

So yeah, that was easier than I thought.

推荐答案

我已经找到了解决方案!一种是完全相对其自身,并且在所有的不依赖于像素或密度的像素。

I have found a solution! One that is completely relative to itself, and does not rely on pixels or density pixels at all.

我已经放在为0x0的一个TextView在屏幕中间,并把RelativeLayouts上的和它下面顶部,填充屏幕。

I've placed a TextView of 0x0 in the middle of the screen, and put RelativeLayouts on top of and below it, filling the screen.

然后我把为0x0两种TextViews这些布局的中间,这些布局中,两个新RelativeLayouts。下面的一个最高的TextView,一个在上最低的。我把这些布局的中心,我的按钮。

Then I placed two TextViews of 0x0 in the middle of those layouts, and within those layouts, two new RelativeLayouts. One below the highest TextView, one above the lowest. I placed my buttons in the center of those layouts.

它的工作原理就像一个魅力,而且不依赖于任何东西,但code本身。

It works like a charm, and does not rely on anything but the code itself.

这是我的code现在:

This is my code now:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="@drawable/mainbg">


    <TextView 
        android:text=" "
        android:id="@+id/ankermidden"
        android:layout_centerVertical="true"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </TextView>

    <RelativeLayout
        android:id="@+id/ankerveldboven"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/ankermidden">

                <TextView 
                    android:text=" "
                    android:id="@+id/ankerboven"
                    android:layout_centerVertical="true"
                    android:layout_width="0dp"
                    android:layout_height="0dp">
                </TextView>

            <RelativeLayout
                android:id="@+id/ankerveldmidboven"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/ankerboven">

                 <Button 
                    android:text="@string/topbutton"
                    android:background="@drawable/silvertablesbuttonbgkort"
                    android:id="@+id/topbutton"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center|center_vertical">
                </Button>

            </RelativeLayout>

</RelativeLayout>


<RelativeLayout
        android:id="@+id/ankerveldonder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/ankermidden">

    <TextView 
        android:text=" "
        android:id="@+id/ankeronder"
        android:layout_centerVertical="true"
        android:layout_width="0dp"
        android:layout_height="0dp">
    </TextView>

            <RelativeLayout
                android:id="@+id/ankerveldmidonder"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/ankeronder">      

                <Button 
                    android:text="@string/midbutton"
                    android:background="@drawable/silvertablesbuttonbglang"
                    android:id="@+id/midbutton"
                    android:layout_alignParentRight="true" 
                    android:layout_centerInParent="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center|center_vertical">
                </Button>

            </RelativeLayout>       

 </RelativeLayout>

<RelativeLayout 
    android:id="@+id/underbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button 
        android:text="@string/underbartekst"
        android:background="@drawable/silvertablesunderbar"
        android:id="@+id/underbarbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:textSize="20dp"
        android:gravity="left|center_vertical" >
    </Button>

</RelativeLayout>

所以是的,这是比我想象的更容易。

So yeah, that was easier than I thought.

比尔加里使用DP保证金这将保持相同的比例在不同屏幕尺寸的建议,但很多实验后,事情结束了,我在不同的屏幕上再次寻找怪异。

Bill Gary suggested using a margin in dp which would keep the same proportions on different screen sizes, but after a lot of experimenting, things end up looking weird for me on different screens again.

我会做一些尝试多前我会回来的,因为这整个浸利润的事情是weirding我出去......事情,应该正确显示都没有,事,只是不应该,这样做,在一些屏幕分辨率。

I'll do some more experimenting before I'll get back to that, because this whole dip-margins thing is weirding me out... Things that should be displayed properly are not, and things that just shouldn't, do, on some screen resolutions.

我就开始做功课上的东西,但现在,尽管它是一个有点长,code我上面贴的作品完美的我。

I'll start doing my homework on that stuff, but for now, albeit it being a bit long, the code I posted above works flawlessly for me.

这篇关于怎样才能在屏幕的某些位置对齐的意见,住在多个屏幕分辨率是否一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆