Jack
Jack

Reputation: 135

Can't align text to the right in the layout

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="70dp"
            android:layout_height="55dp"
            android:text="nope"
            android:id="@+id/cancel_arrive"
            android:onClick="selectNotGoing"
             />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1">

        <TextView
            android:id="@+id/attendingEventInListviewRow"
            android:layout_width="match_parent"
            android:layout_height="28dp"
            android:text="eventsName"
            android:height="30sp"
            android:textSize="22sp"
            android:gravity="right"
            android:tag="eventsName"
            />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="eventDayOfTheWeek"
        android:textColor="#000000"
        android:id="@+id/eventDayOfTheWeekTxt"
            android:gravity="right"

            />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="eventTime"
        android:textColor="#000000"
        android:id="@+id/eventTimeTxt"
        android:gravity="right"
        />

    </LinearLayout>


</LinearLayout>

I have tried to google the problem and implement solutions I have found in here. Nothing helped. The code above is my current XML. I need eventName, eventDayOfTheWeek and eventTime to stay in the right side.

I have also tried to clean the project and rebuild it, but it stays the same.

(In the preview the text is in the right side, after the launch it goes to the left)

Before launch(In the preview): http://prntscr.com/db0ekp After launch: http://prntscr.com/db0f7t

(The layout is a row inside a list view)

Upvotes: 1

Views: 97

Answers (1)

snachmsm
snachmsm

Reputation: 19243

preview shows your layout without info where it will be inflated, assumes as "wholescreen" layout. but your XML code is piece inside container (ListView), which may have set layout_width to wrap_content (or fixed value). your ListView should have match_parent (and maybe its parent too). show more code, especially for Activity or Fragment if you are using.

Upvotes: 1

Related Questions