Android 为什么我的直线布局中的行不放在顶部?
我有一个复杂的XML布局Android 为什么我的直线布局中的行不放在顶部?,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我有一个复杂的XML布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/mainbackground" android:orientation="vertical" android:weightSu
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/mainbackground"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:id="@+id/selector"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:text="@string/month" />
<TextView
android:id="@+id/byday"
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@color/tertiarybackground"
android:gravity="center"
android:text="@string/day"
android:textColor="@color/links" />
</LinearLayout>
<RelativeLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/selector"
android:layout_weight="0.1"
android:background="@color/mainbackground" >
<RelativeLayout
android:id="@+id/previous"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentLeft="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/arrow_left" />
</RelativeLayout>
<TextView
android:id="@+id/title"
style="@style/H2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"
android:textColor="#000000" />
<RelativeLayout
android:id="@+id/next"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentRight="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/arrow_right" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/daysoftheweek"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/header"
android:layout_weight="0.05"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sun" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mon" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tue" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wed" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/thu" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fri" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sat" />
</LinearLayout>
</LinearLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:fadeScrollbars="false"
android:gravity="top"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="0" >
<LinearLayout
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="top"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
这是我得到的结果。
如您所见,该行位于中间,而不是文本的顶部
LinearLayout
谢谢你的帮助 对线性布局使用layout\u gravity=“top”属性
<LinearLayout
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="top"
android:orientation="vertical" >
</LinearLayout>
已解决
问题出现在上面的GridView中:
我更改了表格:
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
到
是的,layou gravity
和gravity
@Sinu Varghese感谢Sinu,我确实按照你的建议做了,但得到了同样的结果。没有成功:-(((
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />