【问题标题】:How to align an image-view for all android screens如何为所有 android 屏幕对齐图像视图
【发布时间】:2015-07-02 16:46:18
【问题描述】:

我想对齐一个图像视图,该图像视图在所有 Android 屏幕上都显示相同,对于 Android 选项卡屏幕而言。当应用程序在模拟器或实时设备上运行时,会注意到 imageview 的不同对齐方式。我如何正确对齐它们??

这是我的activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#fff" >

<ImageView
    android:id="@+id/forts"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="150dp"
    android:src="@drawable/forts" />

<ImageView
    android:id="@+id/portal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/forts"
    android:layout_below="@+id/forts"
    android:src="@drawable/portal" />

<ImageView
    android:id="@+id/emergency"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/forts"
    android:layout_toRightOf="@+id/portal"
    android:src="@drawable/emergency" />

<ImageView
    android:id="@+id/aboutus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/portal"
    android:layout_toLeftOf="@+id/emergency"
    android:src="@drawable/aboutus" />

<ImageView
    android:id="@+id/maps"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/emergency"
    android:layout_alignLeft="@+id/emergency"
    android:src="@drawable/maps" />

<ImageView
    android:id="@+id/mailus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/emergency"
    android:layout_alignTop="@+id/aboutus"
    android:src="@drawable/mailus" />

</RelativeLayout>

【问题讨论】:

  • 您可以使用drawable文件夹和dimen文件夹来放置不同的图像mdpi、hdpi、ldpi、xhdpi等

标签: android imageview alignment


【解决方案1】:

使用不同类型的图像,即 ldpi、mdpi、hdpi、xhdpi、xxhdpi。

【讨论】:

    【解决方案2】:

    对于不同的屏幕尺寸和不同的密度图像会有所不同。 为了将图像拟合到 imageview 用户中,

    android:scaleType="fitXY" 
    

    如果您希望您的 imageview 类似于所有设备,您需要为不同的屏幕尺寸和不同的图像(如 ldpi、hdpi、mdpi)为不同的密度创建不同的布局文件夹。

    【讨论】:

      【解决方案3】:

      您可以将不同值文件夹中的变量维度设置为

      1:values    
          -dimens.xml    
           <dimen name="image_email_width">45dp</dimen>
              <dimen name="image_email_height">35dp</dimen>
      
      2:values-xlarge
      -dimens.xml   
      
           <dimen name="image_email_width">90dp</dimen>
              <dimen name="image_email_height">70dp</dimen>
      

      然后将您的 Imageview 设置为

      <ImageView
          android:id="@+id/portal"
          android:layout_width="@dimens/image_email_width"
          android:layout_height="@dimens/image_email_height"
          android:layout_alignLeft="@+id/forts"
          android:layout_below="@+id/forts"
          android:src="@drawable/portal" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-17
        • 1970-01-01
        • 2011-01-24
        • 1970-01-01
        • 2018-02-25
        • 2018-01-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多