dc10
dc10

Reputation: 2208

How to align a nested LinearLayout to top

I have a RelativeLayout within a LinearLayout and for some reason I can not get rid off the padding between the text and divider line of the first row. How is it possible to align the Text / LinearLayout to the top?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/file_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="top"
android:baselineAligned="false">

<ImageView
    android:id="@+id/file_row_thumb"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_weight="0"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:scaleType="fitStart" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical">

    <TextView
        android:id="@+id/file_row_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/file_row_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12dp" />

</LinearLayout>

<ImageButton
    android:scaleType="fitStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_weight="0"
    android:background="?android:selectableItemBackground"
    android:onClick="showFilePopup"
    android:src="@drawable/ic_more_vert" />

unwanted padding

Studio preview shows dotted line. Is it responsible for the padding?

enter image description here

Upvotes: 3

Views: 984

Answers (1)

Gary99
Gary99

Reputation: 1770

Add these 2 lines to your TextView:

    android:height="16dp"
    android:gravity="bottom|clip_vertical"

That will push the text to the top of it's view. If you want to have it actually touching the view above, you can reduce height.

Here are a couple of screenshots:

1st with height=16height = 16

And an exaggerated one with height=14enter image description here

And here's a link to give you other various XML attributes for TextView

developer.android.com/reference/android/widget/TextView.html

Upvotes: 2

Related Questions