2017-02-12 3 views
0

Я не могу пронести вправо, Horizontalscrollview не работает.HorizontalScrollview не работает Андроид

Я представил предварительный просмотр XML ниже, у меня нет java-кодов, поэтому я предоставлял только коды XML.

Проблема: у меня есть 5 кнопок в верхней части фрагмента карты Google, я не могу дойти до пятой кнопки, потому что horizonalscrollview не работает.

Вот предварительный просмотр XML: http://imgur.com/a/QqTZn

Вот это XML:

<RelativeLayout 

    android:layout_height="wrap_content" 
    android:layout_width="500dp" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout 
    android:layout_width="500dp" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/linearLayout"> 

    <HorizontalScrollView 

     android:layout_width="500dp" 
     android:layout_height="50dp" 
     android:background="#BEFFB6" 
     android:layout_marginTop="0dp" 
     android:id="@+id/horizontalScrollView"> 

     <LinearLayout 

      android:layout_width="match_parent" 
      android:layout_height="50dp" android:orientation="horizontal" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true"> 


      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Building 1" 
       android:id="@+id/p1" 
       android:onClick="b1" 
       android:layout_above="@+id/place_autocomplete_fragment" 
       android:layout_alignParentStart="true" /> 

      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Building 2" 
       android:onClick="b2" 
       android:id="@+id/p2" 
       android:layout_above="@+id/place_autocomplete_fragment" 
       android:layout_alignParentStart="true" /> 

      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Building 3" 
       android:onClick="b3" 
       android:id="@+id/p3" 
       android:layout_above="@+id/place_autocomplete_fragment" 
       android:layout_alignParentStart="true" /> 

      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Building 5 " 
       android:id="@+id/p5" 
       android:onClick="b5" 
       android:layout_above="@+id/place_autocomplete_fragment" 
       android:layout_alignParentStart="true" /> 

      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="P.E center" 
       android:id="@+id/p4" 
       android:onClick="pecenter" 
       android:layout_above="@+id/place_autocomplete_fragment" 
       android:layout_alignParentStart="true" /> 

     </LinearLayout> 
    </HorizontalScrollView> 
</LinearLayout> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:map="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="380dp" 

     android:layout_height="450dp" 
     tools:context="com.sumo.traffic.traffic" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@+id/linearLayout" /> 


</RelativeLayout> 

ответ

0

Это происходит потому, что вы используете статические размеры ширины контейнера изображен, поэтому контейнер показаны частично выключить экран. Вы должны установить относительную ширину. В этом случае, если вы хотите иметь ScrollView большой, как на экране, вы должны установить значение match_parent атрибут android:layout_width первого RelativeLayout, в LinearLayout внутри и HorizontalScrollView:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <HorizontalScrollView 
      android:id="@+id/horizontalScrollView" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_marginTop="0dp" 
      android:background="#BEFFB6"> 

      <!-- content --> 

     </HorizontalScrollView> 
    </LinearLayout> 

    <!-- fragment --> 

</RelativeLayout> 
Смежные вопросы