简体   繁体   中英

Alignment issue for textview in android

I am trying to get the text "Your token is run out, please reconnect" little up just below the icon and title of "facebook" and "twitter" but there is lot of gap between them. I tried all possible ways but not sure where m missing. Below is my code n screenshot.

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

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:gravity="center_vertical"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingLeft="10dip"
                    android:src="@drawable/facebook" />

                <TextView
                    android:id="@+id/list"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="center_vertical"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:paddingLeft="10dip"
                    android:text="Facebook"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#444444"
                    android:textSize="20sp" />

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:paddingRight="15dip"
                    android:src="@drawable/ok" />
            </LinearLayout>

            <TextView android:id="@+id/tokentextfacebook"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/facebook"   
                    android:textSize="14sp"
                    android:paddingLeft="10dip"
                    android:background="#ffffff"
                    android:text="Your token is run out. Please reconnect"
                    android:textColor="#444444"
                    android:gravity="left"
                />

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray"/>

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingLeft="10dip"
                    android:src="@drawable/twitter" />

                <TextView
                    android:id="@+id/list"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="center_vertical"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:paddingLeft="10dip"
                    android:text="Twitter"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#4a82ae"
                    android:textSize="20sp" />

                <ImageView
                    android:id="@+id/twitter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:paddingRight="15dip"
                    android:src="@drawable/ok" />
            </LinearLayout>

            <TextView android:id="@+id/tokentexttwitter"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/facebook"   
                    android:textSize="14sp"
                    android:paddingLeft="10dip"
                    android:background="#ffffff"
                    android:text="Your token is run out. Please reconnect"
                    android:textColor="#444444"
                    android:gravity="left"
                />

        </LinearLayout>
    </LinearLayout>

使用RelativeLayout可以更轻松地实现此设计,但是无论如何,您都可以在TextView上使用负边距正确定位它。

android:layoutMarginTop="-10dp"

Try

android:paddingBottom="30dip"

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

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:gravity="center_vertical"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingLeft="10dip"
                    android:src="@drawable/facebook" />

                <TextView
                    android:id="@+id/list"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="center_vertical"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:paddingLeft="10dip"
                    android:text="Facebook"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#444444"
                    android:textSize="20sp" />

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:paddingRight="15dip"
                    android:src="@drawable/ok" />
            </LinearLayout>

            <TextView android:id="@+id/tokentextfacebook"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/facebook"   
                    android:textSize="14sp"
                    android:paddingLeft="10dip"
                    android:background="#ffffff"
                    android:text="Your token is run out. Please reconnect"
                        android:paddingBottom="30dip"
                    android:textColor="#444444"
                    android:gravity="left"
                />

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray"/>

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/facebook"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingLeft="10dip"
                    android:src="@drawable/twitter" />

                <TextView
                    android:id="@+id/list"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="center_vertical"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:paddingLeft="10dip"
                    android:text="Twitter"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#4a82ae"
                    android:textSize="20sp" />

                <ImageView
                    android:id="@+id/twitter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:paddingRight="15dip"
                    android:src="@drawable/ok" />
            </LinearLayout>

            <TextView android:id="@+id/tokentexttwitter"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/facebook"   
                    android:textSize="14sp"
                    android:paddingLeft="10dip"
                    android:background="#ffffff"
                    android:text="Your token is run out. Please reconnect"
                    android:textColor="#444444"
                        android:paddingBottom="30dip"
                    android:gravity="left"
                />

        </LinearLayout>
    </LinearLayout>

Probelm iw with your min height criteria at wrong place, use this layout just modifed.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/facebook"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingLeft="10dip"
                android:src="@drawable/facebook" />

            <TextView
                android:id="@+id/list"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:gravity="center_vertical"
                android:paddingLeft="10dip"
                android:text="Facebook"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#444444"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/facebook"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_vertical"
                android:paddingRight="15dip"
                android:src="@drawable/ok" />
        </LinearLayout>

        <TextView
            android:id="@+id/tokentextfacebook"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/facebook"
            android:layout_gravity="top"
            android:background="#ffffff"
            android:gravity="left"
            android:paddingLeft="10dip"
            android:text="Your token is run out. Please reconnect"
            android:textColor="#444444"
            android:textSize="14sp" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/facebook"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingLeft="10dip"
                android:src="@drawable/twitter" />

            <TextView
                android:id="@+id/list"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:gravity="center_vertical"
                android:paddingLeft="10dip"
                android:text="Twitter"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#4a82ae"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/twitter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_vertical"
                android:paddingRight="15dip"
                android:src="@drawable/ok" />
        </LinearLayout>

        <TextView
            android:id="@+id/tokentexttwitter"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/facebook"
            android:background="#ffffff"
            android:gravity="left"
            android:paddingLeft="10dip"
            android:text="Your token is run out. Please reconnect"
            android:textColor="#444444"
            android:textSize="14sp" />
    </LinearLayout>



</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM