简体   繁体   中英

Android Views: Getting a view to snap to the left hand side of the screen

I have 2 views one is a scroll view and the other is a LinearLayout. I want the LinearLayout to be a fixed size, i have it about 80dp. I want this layout to be on the right hand side of my screen the whole time. The rest of the space i want my Scroll View to take up. Here is what my code looks like.

     <LinearLayout
    android:id="@+id/widget4327"
    android:layout_below="@+id/line"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#F4F5DC">


<ScrollView 
    android:id="@+id/ScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:layout_below="@+id/line">

</ScrollView>

<LinearLayout
    android:id="@+id/linearL2"
    android:background="#EEEFE0"
    android:layout_gravity="right"
    android:layout_height="fill_parent"
    android:layout_width="80dp"
    android:orientation="vertical"
    android:gravity="left"
    android:layout_toRightOf="@id/ScrollView01">

</LinearLayout>

</LinearLayout>

I thought the gravity would take care of this but i cant seem to get it working. Any ideas?

如果使用RelativeLayout则可以将alignToParentLeft设置为true

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