2016-06-08 40 views
0

如何將scrollview插入到此目錄中,並且仍然保留我的應用程序的標題?此外,所有教程似乎都要求您切換到LinearLayout,並且LinearLayout使我很難格式化需要包含在活動中的所有按鈕和文本框。我需要設計一個帶有滾動視圖的android活動

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="washingtondeli.groupboxlunchesestimateandordering.CapitolhillActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Capitol Hill Picnic Box Lunch" 
     android:id="@+id/capitolhilltitle" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 
+0

出了什麼問題?只需將您的TextView包裝在scrollView中即可。此外,習慣使用LinearLayouts,通常它們會更加一致地在不同的設備上查看RelativeLayouts。 – Vucko

+0

看看這個問題:http://stackoverflow.com/questions/6674341/how-to-use-scrollview-in-android – KevinTheGreat

回答

3

第1步:使滾動型根佈局

步驟2添加的LinearLayout您滾動型

記住,滾動型只接受1名兒童

然後只需添加您的LinearLayout內的按鈕 - 順便說一下,其他LinearLayouts可以支持不同的佈局樣式,然後您擁有權重t o相應地放置您的物品!

您還可以查看其他選項。哦,幾乎忘了這個:閱讀一些教程,以幫助你開始!

我希望這有助於!

+0

感謝您的幫助。我正在嘗試添加按鈕,現在我處於線性視圖,它不再讓我拖放東西 – Casey

0

您可以在滾動視圖中使用相對佈局, 下面是一個示例,對於相對佈局滾動視圖具有固定頭

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <TextView 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:text="Header" 
     android:textColor="#ffffff" 
     android:textSize="22dp" /> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_below="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="0dp" 
     android:fillViewport="true" > 

     <RelativeLayout 
      android:id="@+id/filt_top" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:animateLayoutChanges="true" > 

      //your scrollable contents here 

     </RelativeLayout> 

    </ScrollView> 

    </RelativeLayout> 
相關問題