调整为不同的屏幕尺寸在Android中的进度条 [英] Aligning a progress bar in Android for different screen sizes

查看:117
本文介绍了调整为不同的屏幕尺寸在Android中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发的有闪屏的应用程序,你可以看到它下面的图片。
我的问题是,我需要把一个进度条,你可以在下面的图片中没有太多的布局看,因为现在我为了得到这种效果8布局(布局sw320dp,布局sw320dp土地,布局sw480dp ,布局sw480dp土地... 600720)。
我试图用相对布局和中心水平进度条,但有不同的屏幕尺寸进度条让其他位置处上下。

我能以较少的文件夹解决呢?

这是我的布局文件320dp:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:ID =@ + ID / RelativeLayout1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@绘制/ splash_screen_land
    机器人:方向=垂直>    <进度
        机器人:ID =@ + ID / progressBar1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginBottom =24dp/>< / RelativeLayout的>


解决方案

我建议你只使用一个布局文件,比方说 splash.xml 。放在一个 RelativeLayout的你的的ImageView 的android:layout_centerInParent =真正的。那么你的进度的android:下面=@ ID /图片来把它比较下面的图片。您可以更改布局 paddingBottom会在布局的中心进行调整的意见。

 < RelativeLayout的
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:paddingBottom会=@扪/ padding_bottom>
    < ImageView的
        机器人:ID =@ ID /图像
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerInParent =真/>
    <进度
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ ID /图像
        安卓了minHeight =@扪/ progress_height
        安卓了minWidth =@扪/ progress_height/>
< / RelativeLayout的>

现在不是有很多的布局,你能不能让上面的布局,并根据您的屏幕尺寸创造了许多价值。含义:


  • 值/ dimens.xml

  • 价值观大/ dimens.xml

  • 价值观土地/ dimens.xml


因此​​,您的视图的布局将不是来自屏幕切换到另一个,只有他们的规模将!

I am developing an app which has a splash screen, you can see it in the picture below. My problem is that I am needing to put a progress bar as you can see in the picture below without many layouts, because now I have eight layout in order to get this effect (layout-sw320dp, layout-sw320dp-land, layout-sw480dp, layout-sw480dp-land...600,720). I was trying use relative layout and center horizontally the progress bar, but with different screen sizes the progress bar get other position vertically.

Could I solve it with less folders?

This is my layout file for 320dp:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_screen_land"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="24dp" />

</RelativeLayout>

解决方案

I suggest you use just one layout file, let's say splash.xml. Put in a RelativeLayout your ImageView, with android:layout_centerInParent="true". Then your ProgressBar with android:below="@id/image" to put it relatively below the image. You can change the layout paddingBottom to adjust views in the center of the layout.

<RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/padding_bottom">
    <ImageView 
        android:id="@id/image" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" />
    <ProgressBar 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/image"
        android:minHeight="@dimen/progress_height"
        android:minWidth="@dimen/progress_height" />
</RelativeLayout>

Now instead of having many layouts, you will keep the above layout, and create many values according to your screen sizes. Meaning :

  • values/dimens.xml
  • values-large/dimens.xml
  • values-land/dimens.xml
  • etc.

Thus, your view's layout won't change from a screen to another, only their size will !

这篇关于调整为不同的屏幕尺寸在Android中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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