0

After looking in google and in the from for set boundaries to fit text in RelativeLayout to the button size.

example from my app: http://tinypic.com/view.php?pic=2wec9d5&s=8#.VUZns_lVhBc

My xml button:

<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:background="@drawable/bg_game"
    tools:context=".ClassicMode" >
    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="10dp"
        android:scaleType="fitXY"
        android:scaleX="2"
        android:scaleY="2" />

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal" >
    </LinearLayout>

    <TextView
        android:id="@+id/numOfGuesses"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="23dp"
        android:layout_toLeftOf="@+id/linearLayout1"
        android:layout_toRightOf="@+id/gallery1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/guesses"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/guesses"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="60px" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="23dp"
        android:layout_marginTop="18dp"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="226dp"
            android:layout_height="152dp"
            android:scaleX="1"
            android:scaleY="1"
            android:src="@drawable/argentina" />
    </LinearLayout>

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:onClick="check"
        android:scaleX="1.5"
        android:scaleY="1.5"
        android:text="Button"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:onClick="check"
        android:scaleX="1.5"
        android:scaleY="1.5"
        android:text="Button"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button3"
        android:layout_below="@+id/button3"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:onClick="check"
        android:scaleX="1.5"
        android:scaleY="1.5"
        android:text="Button"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_below="@+id/button2"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:onClick="check"
        android:scaleX="1.5"
        android:scaleY="1.5"
        android:text="Button"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/scorenum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/linearLayout1"
        android:layout_alignParentLeft="true"
        android:textSize="60px" />

    <TextView
        android:id="@+id/score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/scorenum"
        android:layout_alignParentLeft="true"
        android:text="@string/score"
        android:textSize="60px" />

    <Button
        android:id="@+id/hint"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/circle"
        android:gravity="center_vertical|center_horizontal"
        android:text="hint"
        android:textColor="#fff" />

</RelativeLayout>
Community
  • 1
  • 1
Adi
  • 27
  • 8

1 Answers1

0

Try setting following properties on your buttons:

android:layout_marginRight="0dp"
android:layout_marginLeft="0dp"
android:singleLine="false" // set this to true if you want your text to be single line
                           // or to false otherwise

And I suggest removing this line from your buttons:

android:layout_alignLeft="some_button_id"
questioner
  • 2,283
  • 3
  • 26
  • 35
  • still it goes out of bounderis but a littel bit better i think just one word going out – Adi May 03 '15 at 19:18
  • @Adi Could you paste here another screenshot and point out which buttons goes out of scope? – questioner May 03 '15 at 19:27
  • @Adi Actually when I paste your code into my editor - it looks fine. No adjustments needed. Are you sure you're not changing your buttons style from code? – questioner May 03 '15 at 20:42
  • ive changed what you told me to change or to add as layoutMarginiLeft/Right i didnt touch the style i mean – Adi May 04 '15 at 06:09