2015-11-10 3 views
1

Я хочу добавить вид прокрутки к относительной компоновке, потому что у меня было больше кнопок, когда я увеличивал количество кнопок и запускал их на своем мобильном устройстве. Я не видел некоторых кнопок, поэтому хочу добавить прокрутку для кнопки. Как я могу добавить его? Ниже мой XML-кодЯ хочу добавить Свиток в Buuton?

<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=".MainActivity" 
     android:background="@drawable/background1"> 

     <include layout="@layout/header" /> 

     <include layout="@layout/footer" /> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/header" 
      android:layout_above="@+id/footer" 
    > 

       <Button 
        android:id="@+id/templesbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Historical" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_marginTop="10dp"/> 
       <Button 
        android:id="@+id/resortsbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Resorts" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/templesbtn"/> 
       <Button 
        android:id="@+id/shoppingmallsbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Shopping" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/resortsbtn"/> 
       <Button 
        android:id="@+id/theatersbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Theaters" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/shoppingmallsbtn"/> 
       <Button 
        android:id="@+id/restaurantsbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Restaurants" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/theatersbtn" 
        /> 

       <Button 
        android:id="@+id/hospitalbtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Hospitals" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/restaurantsbtn" 
        /> 

        <Button 
        android:id="@+id/collegebtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Colleges" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/hospitalbtn" 
        /> 
        <Button 
        android:id="@+id/onlineservicebtn" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:text="Online Services" 
        style="?android:attr/buttonStyleSmall" 
        android:background="@drawable/mymenubuttons" 
        android:layout_marginBottom="10dp" 
        android:layout_below="@+id/collegebtn" 
        /> 



     <RelativeLayout 
      android:layout_toRightOf="@+id/templesbtn" 
      android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    <GridView 
     android:id="@+id/gridView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:numColumns="2" 
     android:visibility="invisible" > 
    </GridView> 

</RelativeLayout> 

    </RelativeLayout> 


</RelativeLayout> 

кто может мне помочь?

+0

просто оберните относительный макет, содержащий ваши кнопки, с прокруткой. – Bhargav

+0

Но в моем относительном расположении есть еще один относительный макет –

+0

и есть один относительный макет, обертывающий ваши кнопки, насколько я могу видеть из вашего кода, просто оберните это относительная компоновка с видом прокрутки – Bhargav

ответ

0

Для получения более подробной информации о Scroll View visit

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    // your child View 
     // Buttons inside child View 

</ScrollView> 
+0

Но я написал кнопки в относительном макете, а идентификатор первой кнопки присваивается другому макету –

+0

, вы можете добавить это в свой относительный макет и затем поместите кнопки внутри него –

+0

Я попробовал это, но он показывает ошибку –

1

Сначала оберните все кнопки с LinearLayout (по вертикали), а затем завернуть, что с Scrollview:

 <RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <LinearLayout 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
<Button 
       android:id="@+id/templesbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Historical" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_marginTop="10dp"/> 
      <Button 
       android:id="@+id/resortsbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Resorts" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/templesbtn"/> 
      <Button 
       android:id="@+id/shoppingmallsbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Shopping" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/resortsbtn"/> 
      <Button 
       android:id="@+id/theatersbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Theaters" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/shoppingmallsbtn"/> 
      <Button 
       android:id="@+id/restaurantsbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Restaurants" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/theatersbtn" 
       /> 

      <Button 
       android:id="@+id/hospitalbtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Hospitals" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/restaurantsbtn" 
       /> 

       <Button 
       android:id="@+id/collegebtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Colleges" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/hospitalbtn" 
       /> 
       <Button 
       android:id="@+id/onlineservicebtn" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:text="Online Services" 
       style="?android:attr/buttonStyleSmall" 
       android:background="@drawable/mymenubuttons" 
       android:layout_marginBottom="10dp" 
       android:layout_below="@+id/collegebtn" 
       /> 

     </LinearLayout> 
    </ScrollView> 


    <RelativeLayout 
     android:layout_toRightOf="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:numColumns="2" 
      android:visibility="invisible"></GridView> 

    </RelativeLayout> 

</RelativeLayout> 
+0

Спасибо, что он отлично работает –

+0

Если это работало, не стесняйтесь отмечать как ответ :) – TdSoft

0

Может вы могли бы использовать ListView addHeaderView и addFooterView вместо ScrollView.

Смежные вопросы