19

I can't see any tag to set width

Here I set textview height, if I set width it will not work properly.

<TextView
   android:id="@+id/nome"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textColor="#FFFFFF"
   android:drawableLeft="@drawable/ic_launcher"
   android:height="50dp" />

How can I set this in xml? Is it possible?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rafael Oliveira
  • 191
  • 1
  • 5
  • What exactly is your question? What is not working? What errors are you getting? ect – 0gravity Aug 08 '12 at 23:15
  • I want set the image size to 50dp/50dp – Rafael Oliveira Aug 08 '12 at 23:19
  • you have two viable answers. hence -1 – Code Droid Aug 09 '12 at 00:24
  • You can achieve this by creating the right size images for each dimension. For mdpi you should use 50px by 50px, for hdpi you should use 75px by 75px, or xhdpi you should use 100px by 100px. The TextView will use the intrinsic size of these images. – Matt Accola Feb 07 '13 at 17:20
  • 15
    This question should not be closed , the question is VERY clear and one of the top search results on the topic. Stack really needs some better admins – ChuckKelly May 04 '14 at 03:26
  • @ChuckKelly It is possible to do it with custom view. It is additional code, but only once. See my comment - http://stackoverflow.com/a/31916731/2308720 – Oleksandr Aug 10 '15 at 10:07

2 Answers2

2

You can try something like:

<?xml version="1.0" encoding="utf-8"?>
<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" >


<TextView
    android:id="@+id/Home"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:text="Something"
    android:textColor="#FFFFFF" />

<ImageView 
    android:src="@drawable/icon" 
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_toLeftOf="@id/Home"/>

</RelativeLayout>

This way I think you would have more control of your image. Hope that helps.

0gravity
  • 2,682
  • 4
  • 24
  • 33
-2

try setting to android:width="50dip" and see what you get. dip is device independent pixels. You should be able to see in eclipse in design view. You cannot just set to "300"

Kaushik
  • 6,150
  • 5
  • 39
  • 54
Code Droid
  • 10,344
  • 17
  • 72
  • 112