2010-08-13 115 views
3

我以前問我還一直沒能解決一個問題:Android:即使視圖滾動,如何將廣告對齊到屏幕底部?

http://stackoverflow.com/questions/3126347/android-relativelayout-how-to-alignparentbottom-when-wrapped-in-a-scrollview 

我所試圖做的是對準着眼於屏幕的底部,使用一個的RelativeLayout或LinearLayout中,然後在滾動視圖中包裹該佈局以允許在必要時進行滾動(用於更改橫向或小屏幕設備)。

到目前爲止,我發現任何對齊父母底部的東西都很好,只要底部可見即可...但如果底部位於滾動下方,則對齊父母底部的視圖會跳轉到頂部。

對於出現在底部的廣告,這看起來很常見,所以我認爲這是可能的。是嗎?

回答

12

我不知道是否有一種方法來做到這一點,但這是我用來做這種東西的一個技巧。如果這是你想要什麼:
alt text http://img594.imageshack.us/img594/3419/scrollviewandads.png
這是我爲它的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:id="@+id/scrollAds"> 
<ScrollView android:id="@+id/scrollView" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_marginBottom="50dip"> 
    <TextView android:id="@+id/tvInScroll" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae metus ac leo ultrices placerat. Curabitur vel ipsum vitae urna ultricies rhoncus. Proin tempus felis nec turpis feugiat vitae vestibulum arcu faucibus. Donec dapibus mi at nisl mattis a malesuada lectus feugiat. Etiam ultricies adipiscing nisi, sed scelerisque mauris ultricies sagittis. Proin blandit dignissim magna, id consectetur justo molestie in. Nullam id nunc et sem dictum malesuada ac et libero. Integer vitae mattis est. Nulla sodales dolor nec metus tempor a vestibulum nisl pellentesque. Suspendisse interdum, risus non pulvinar aliquet, tellus elit sodales ligula, vitae mollis nisi massa eget purus. Etiam pharetra consectetur ipsum, eu pretium est egestas eu. Vivamus varius tortor ac leo gravida tempus. Ut semper scelerisque vestibulum. Morbi pretium neque vel neque tempus tempus. Proin tellus tortor, posuere nec dignissim in, venenatis hendrerit augue. Etiam eget justo a nisl semper lobortis. Etiam cursus sodales ipsum non sagittis. Vivamus non metus augue, vehicula iaculis tortor. Aenean tristique orci id lorem consequat vitae commodo metus auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae metus ac leo ultrices placerat. Curabitur vel ipsum vitae urna ultricies rhoncus. Proin tempus felis nec turpis feugiat vitae vestibulum arcu faucibus. Donec dapibus mi at nisl mattis a malesuada lectus feugiat. Etiam ultricies adipiscing nisi, sed scelerisque mauris ultricies sagittis. Proin blandit dignissim magna, id consectetur justo molestie in. Nullam id nunc et sem dictum malesuada ac et libero. Integer vitae mattis est. Nulla sodales dolor nec metus tempor a vestibulum nisl pellentesque. Suspendisse interdum, risus non pulvinar aliquet, tellus elit sodales ligula, vitae mollis nisi massa eget purus. Etiam pharetra consectetur ipsum, eu pretium est egestas eu. Vivamus varius tortor ac leo gravida tempus. Ut semper scelerisque vestibulum. Morbi pretium neque vel neque tempus tempus. Proin tellus tortor, posuere nec dignissim in, venenatis hendrerit augue. Etiam eget justo a nisl semper lobortis. Etiam cursus sodales ipsum non sagittis. Vivamus non metus augue, vehicula iaculis tortor. Aenean tristique orci id lorem consequat vitae commodo metus auctor. "></TextView> 
</ScrollView> 

<TextView android:layout_width="wrap_content" android:id="@+id/tvBelowScroll" 
    android:text="This is your ads TV" android:layout_height="50dip" 
    android:textStyle="bold" android:textSize="18dip" 
    android:layout_alignParentBottom="true"></TextView> 
</RelativeLayout> 

我希望這符合你的希望;)它只是利潤一招。

+0

謝謝。這工作完美。我需要一種新的方式來看待它,而外部的RelativeLayout就是答案。多謝! – JohnRock 2010-08-14 06:01:20

相關問題