繁体   English   中英

如何在屏幕中央显示imageview?

[英]how to show imageview in center of the screen?

我创建了旋转木马设计应用程序,它工作正常。 我希望在屏幕中央显示一个默认徽标。 所以我尝试了很多方法,请帮助我。

这是我的屏幕截图: 在此输入图像描述

我希望在旋转木马设计的中心显示一个标志。

这是我的xml源代码:

>

<LinearLayout
    android:layout_weight="0.5"
    android:padding="5dip"
    android:gravity="top"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    >
        <com.globems.controls.Carousel
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/carousel"  
            pj:UseReflection="true"
            pj:Items="@array/entries"
            pj:Names="@array/names" 
            pj:SelectedItem="0"
            android:animationDuration="200"
        />    
         <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

</LinearLayout>     

在这段代码中我使用imageview来显示徽标,但它不起作用。

更新了xml:

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

    >

    <RelativeLayout
        android:layout_weight="0.5"
        android:padding="5dip"
        android:gravity="top"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        >
            <com.globems.controls.Carousel
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/carousel"  
                pj:UseReflection="true"
                pj:Items="@array/entries"
                pj:Names="@array/names" 
                pj:SelectedItem="0"
                android:animationDuration="200"
            />    
        <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:centerinHorizontal="true"
        />

    </RelativeLayout>       
</RelativeLayout>

最好使用RelativeLayout并在imageView中添加android:centerinParent="true" ...

更新::

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:pj="http://schemas.android.com/apk/res/com.globems.main"
    xmlns:bm="com.carousel.main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/blue3" >

    <com.globems.controls.Carousel
        android:id="@+id/carousel"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        pj:Items="@array/entries"
        pj:Names="@array/names"
        pj:SelectedItem="0"
        pj:UseReflection="true"
        android:animationDuration="200" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/icon" />

</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM