Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let the ImageView and the TextView the same height

Tags:

android

layout

My layout have ImageView(iv) and TextView(tv). I want to let the tv right of iv. And the tv's height is same as iv's. The tv Gravity set as CENTER_VERTICAL.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"/>


    <TextView
        android:id="@+id/tv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/iv"
        android:text="TextView" android:gravity="center_vertical"/>

</RelativeLayout>

How to arrive the goal?

like image 484
brian Avatar asked Jan 03 '12 08:01

brian


People also ask

How do I center a TextView layout?

If in linearlayout your orientation vertical, you can put the textview in the "horizontal center" by android:layout_gravity="center" . For centering textview vertically you need to set layout_height of textview to match_parent and set android:gravity to "center".

What is SRC in ImageView?

android:scaleType. Controls how the image should be resized or moved to match the size of this ImageView. android:src. Sets a drawable as the content of this ImageView.

Can ImageView be clickable?

Using clickable imagesYou can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.

How do I use ImageView?

For adding an image from Android Studio, Drag the ImageView widget to the activity area of the application, a pop-up dialogue box will open choose from the wide range of drawable resources and click “OK“.


2 Answers

hi try this .....

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/RelativeLayout1"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

  <ImageView
    android:id="@+id/iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_title_home_demo" />

  <TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/iv"
    android:layout_alignTop="@+id/iv"
    android:layout_toRightOf="@+id/iv"
    android:gravity="center_vertical"
    android:text="TextView" />

   </RelativeLayout>
like image 199
loks Avatar answered Sep 27 '22 18:09

loks


You have to set the textview property to android:layout_alignTop="@id/iv" and android:layout_alignBottom="@id/iv"

like image 32
Dharmendra Avatar answered Sep 27 '22 18:09

Dharmendra