简体   繁体   中英

my layout not align properly textview its not show above button

in my code i display week label every thing is fine only weeklabel monday is not align properly seee image http://imgur.com/YJqBje9 . How do i set textview monday properly only i want to show textview above each button how do i do that? monday is not align properly help me please

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="5dp" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TableLayout
        android:id="@+id/table_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:stretchColumns="0,1,2,3,4,5,6" >

        <TableRow
            android:background="#D8D8D8"
            android:paddingBottom="2dp"
            android:paddingLeft="25dp"
            android:paddingRight="25dp" >

            <TextView
                android:id="@+id/mon"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:text="@string/monday"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/tue"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingLeft="17dp"
                android:text="@string/tuesday"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/wed"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/wednesday"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/thur"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingRight="15dp"
                android:text="@string/thursday"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/fri"
                android:layout_weight="1"
                android:gravity="center"
                android:paddingRight="35dp"
                android:text="@string/friday"
                android:textColor="#000000" />
        </TableRow>

        <TableRow>

            <ImageView
                android:id="@+id/last_week"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_gravity="center"
                android:layout_weight="0.5"
                android:background="@drawable/calender_bg"
                android:paddingLeft="5dp"
                android:paddingRight="15dp"
                android:src="@drawable/prevb" >
            </ImageView>

            <Button
                android:id="@+id/e01"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:background="@drawable/calendar_button_selector"
                android:paddingRight="2dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D9DBD7" >
            </Button>

            <Button
                android:id="@+id/e02"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:background="@drawable/calendar_button_selector"
                android:paddingRight="2dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D9DBD7" >
            </Button>

            <Button
                android:id="@+id/e03"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:background="@drawable/calendar_button_selector"
                android:paddingRight="2dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D9DBD7" >
            </Button>

            <Button
                android:id="@+id/e04"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:background="@drawable/calendar_button_selector"
                android:paddingRight="2dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D9DBD7" >
            </Button>

            <Button
                android:id="@+id/e05"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:background="@drawable/calendar_button_selector"
                android:paddingRight="2dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D9DBD7" >
            </Button>

            <ImageView
                android:id="@+id/next_week"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_gravity="center"
                android:layout_weight="0.5"
                android:background="@drawable/calender_bg"
                android:paddingLeft="15dp"
                android:paddingRight="5dp"
                android:src="@drawable/nextb" >
            </ImageView>
        </TableRow>
    </TableLayout>
</LinearLayout>

</LinearLayout>

android:gravity="center"到星期一

In your TableLayout , remove all the padding from all the TextView's except Monday and Friday. Then adjust all the other TextViews (Tuesday, Wednesday, Thursday) by giving them equal padding on left and right. Meaning if you want 20dp padding, give 10 to left, and 10 to the right.

The definition of your first TableRow should be like this.

            <TableRow
                android:background="#D8D8D8"
                android:paddingBottom="2dp">

                <View
                    android:layout_weight="0.5"
                    android:layout_height="match_parent" />

                <TextView
                    android:id="@+id/mon"
                    android:layout_weight="1"
                    android:text="Mon"
                    android:gravity="center"
                    android:textColor="#000000" />

                <TextView
                    android:id="@+id/tue"
                    android:layout_weight="1"
                    android:text="Tue"
                    android:gravity="center"
                    android:textColor="#000000" />

                <TextView
                    android:id="@+id/wed"
                    android:text="Wed"
                    android:gravity="center"
                    android:textColor="#000000" />

                <TextView
                    android:id="@+id/thur"
                    android:layout_weight="1"
                    android:text="Tue"
                    android:gravity="center"
                    android:textColor="#000000" />

                <TextView
                    android:id="@+id/fri"
                    android:layout_weight="1"
                    android:text="Fri"
                    android:gravity="center"
                    android:textColor="#000000" />

                <View
                    android:layout_weight="0.5"
                    android:layout_height="match_parent" />

            </TableRow>

也许摆脱填充并在剩余的几天中添加文本视图,并保留空白文本。

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