mardi 5 mai 2015

Android Layout width of 50%

I am using a relative layout to create an Android UI in XML. The layout is centered around an ImageView and TextView. I need these 2 elements to lay above and below eachother. I want to make it so that these 2 elements take up 50% of the whole width. I tried a LinearLayout with an android:layout_weight=".5" but I couldnt get it it center both horizontally and vertically. Here is the relative layout that I have, I want it to look like this but with the image taking up 50% of the width, with 25% of whitespace on either side. I also need to do it in XML. Any guidance is appreciated.

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    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">

<ImageView
    android:id="@+id/activity_main_imageview_logo"
    android:src="@drawable/img_main_logo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="centerCrop"
    android:paddingBottom="12dp"
    android:onClick="imageViewGTTOnClick"
    android:adjustViewBounds="true" />
<TextView
    android:id="@+id/activity_main_textview_tagline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/activity_main_textview_tagline"
    android:textColor="@color/dark_blue"
    android:gravity="center"
    android:textSize="28sp"
    android:layout_below="@+id/activity_main_imageview_logo"
    android:layout_centerHorizontal="true" />

 </RelativeLayout>

Aucun commentaire:

Enregistrer un commentaire