2017-02-13 19 views
0

У меня есть линейная компоновка, а у самого дна у меня есть gridview (hotelsGrid), что я заполняю больше предметов, чтобы увидеть, проблема в том, что после того, как я установил свой адаптер, вид на экране переходит на снизу, чтобы показать gridview, и мне нужно оставаться на вершине, как я могу архивировать это?Android Gridview получение фокуса

Вот мой XML:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/hotel_detail" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".ActivityHotelDetail"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:background="@color/colorPrimaryDark" 
      android:hapticFeedbackEnabled="true" 
      app:tabGravity="fill" 
      app:tabIndicatorColor="@color/colorPrimary" 
      app:tabIndicatorHeight="3dp" 
      app:tabMode="fixed"/> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_margin="@dimen/activity_vertical_margin" 
       android:background="@drawable/panel_with_border_nopadding" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/hotelName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/fondo_titulo" 
        android:gravity="center" 
        android:paddingBottom="10sp" 
        android:text="Nombre del Hotel" 
        android:textAppearance="@android:style/TextAppearance.Large" 
        android:textColor="@color/textColorPrimary" 
        android:textSize="28sp"/> 

       <ImageView 
        android:id="@+id/hotelMainImage" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:adjustViewBounds="true" 
        android:paddingLeft="1dp" 
        android:paddingRight="1dp" 
        android:scaleType="fitCenter" 
        android:src="@drawable/fondo_360"/> 

       <LinearLayout 
        android:id="@+id/video360" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        android:visibility="gone"> 

        <FrameLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" 
         android:layout_centerHorizontal="true"> 

         <com.google.vr.sdk.widgets.video.VrVideoView 
          android:id="@+id/video_view" 
          android:layout_width="match_parent" 
          android:layout_height="250dip" 
          android:scrollbars="@null"/> 

         <ImageView 
          android:id="@+id/playButton" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center" 
          android:layout_marginBottom="10dip" 
          android:adjustViewBounds="true" 
          android:background="@drawable/playbutton" 
          android:scaleType="fitXY"/> 
        </FrameLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 

         <ImageButton 
          android:id="@+id/play_toggle" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:background="@android:color/transparent" 
          android:paddingStart="0dp" 
          android:paddingTop="4dp" 
          android:src="@drawable/play_on"/> 
         <!-- Seeking UI & progress indicator.--> 
         <SeekBar 
          android:id="@+id/seek_bar" 
          style="?android:attr/progressBarStyleHorizontal" 
          android:layout_width="0dp" 
          android:layout_height="32dp" 
          android:layout_weight="8"/> 

         <ImageButton 
          android:id="@+id/volume_toggle" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:background="@android:color/transparent" 
          android:paddingStart="0dp" 
          android:paddingTop="4dp" 
          android:src="@drawable/volume_on"/> 
        </LinearLayout> 
       </LinearLayout> 

       <TextView 
        android:id="@+id/hotelDistance" 
        android:layout_width="match_parent" 
        android:layout_height="26sp" 
        android:layout_marginBottom="@dimen/activity_vertical_margin" 
        android:layout_marginLeft="1dp" 
        android:layout_marginRight="1dp" 
        android:background="@drawable/fondo_distancia" 
        android:gravity="center" 
        android:text="distance" 
        android:textColor="@color/textColorPrimary"/> 

       <TextView 
        android:id="@+id/hotelAddress" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentStart="true" 
        android:layout_below="@+id/imagepreview" 
        android:layout_marginBottom="@dimen/activity_vertical_margin" 
        android:gravity="center" 
        android:text="Direccion" 
        android:textColor="@color/textColorSecundary"/> 

       <TextView 
        android:id="@+id/hotelDescription" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/activity_vertical_margin" 
        android:gravity="center" 
        android:paddingLeft="@dimen/activity_horizontal_margin" 
        android:paddingRight="@dimen/activity_horizontal_margin" 
        android:text="Descripcion"/> 
      </LinearLayout> 

      <RelativeLayout 
       android:id="@+id/otherHotelsRL" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="@dimen/activity_vertical_margin" 
       android:layout_marginRight="@dimen/activity_vertical_margin" 
       android:layout_marginTop="20dp" 
       android:background="@drawable/panel_with_border_nopadding" 
       android:paddingLeft="1dp" 
       android:paddingRight="1dp"> 

       <TextView 
        android:id="@+id/otherViewsTxt" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:paddingBottom="10dp" 
        android:paddingTop="10dp" 
        android:text="Fotos" 
        android:textColor="@color/textColorSecundary" 
        android:textSize="22sp"/> 

       <HorizontalScrollView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_alignParentStart="true" 
        android:layout_below="@+id/otherViewsTxt" 
        android:layout_marginBottom="10dp" 
        android:fillViewport="true"> 

        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:orientation="horizontal"> 

         <ImageView 
          android:id="@+id/thumb1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginEnd="5dp" 
          android:layout_weight="1" 
          android:src="@mipmap/icon_360"/> 

         <ImageView 
          android:id="@+id/thumb2" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/thumb1" 
          android:layout_marginEnd="5dp" 
          android:layout_weight="1" 
          android:src="@mipmap/icon_360"/> 

         <ImageView 
          android:id="@+id/thumb3" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/thumb2" 
          android:layout_weight="1" 
          android:src="@mipmap/icon_360"/> 
        </LinearLayout> 
       </HorizontalScrollView> 

       <ImageView 
        android:id="@+id/imageView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentStart="true" 
        android:layout_centerVertical="true" 
        android:layout_weight="1" 
        android:alpha="0.8" 
        android:background="#222222" 
        app:srcCompat="@drawable/ic_chevron_left_white_24dp"/> 

       <ImageView 
        android:id="@+id/imageView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentEnd="true" 
        android:layout_centerVertical="true" 
        android:layout_weight="1" 
        android:alpha="0.8" 
        android:background="#222222" 
        app:srcCompat="@drawable/ic_chevron_right_white_24dp"/> 
      </RelativeLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="30dp" 
       android:layout_marginLeft="@dimen/activity_vertical_margin" 
       android:layout_marginRight="@dimen/activity_vertical_margin" 
       android:layout_marginTop="20dp" 
       android:orientation="vertical" 
       android:paddingBottom="1dp" 
       android:paddingLeft="1dp" 
       android:paddingRight="1dp"> 

       <TextView 
        android:id="@+id/otherHotelsTxt" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="5dp" 
        android:background="@drawable/panel_with_border_padding" 
        android:gravity="center" 
        android:paddingBottom="10dp" 
        android:paddingTop="10dp" 
        android:text="Mas Hoteles Interesantes" 
        android:textColor="@color/textColorSecundary" 
        android:textSize="22sp"/> 

       <GridView 
        android:id="@+id/hotelsGrid" 
        android:layout_width="match_parent" 
        android:layout_height="350dp" 
        android:layout_marginTop="@dimen/activity_vertical_margin" 
        android:horizontalSpacing="15dp" 
        android:numColumns="2" 
        android:stretchMode="columnWidth" 
        android:verticalSpacing="15dp"/> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
+0

добавить Focusable: правда и focusableintouch: правда к началу макете. а также положить тега –

+0

Нету .. оно не работало – Chico3001

+0

личного недействительного requestFocus (View вида) { если (view.requestFocus()) { getActivity() GetWindow() setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)..; } } –

ответ

1

добавить к вашему верхнему уровню Layout View --Linearlayout. чтобы сделать его foucsable

<LinearLayout 
android:id="@+id/top_layout" 
android:focusable="true" 
android:focusableInTouchMode="true"> 

В настоящее время в деятельности:

LinearLayout layout = (LinearLayout) findViewById(R.id.top_layout); 
layout.requestFocus(); 

вызов layout.requestFocus(); после и есть Настраивает адаптер

+0

Спасибо .. он работал отлично !!! – Chico3001