2016-08-30 8 views
0

私はボトムシートを作成しようとしましたが、2つの行が含まれています。最初の行は、ユーザーがアプリケーションを開いたときにのみ表示されます。 私はエミュレータでアプリを実行したときには素晴らしいものでしたが、実際のデバイス(Samsung J7)で最初の行と2番目の行の一部が表示されたときに表示されました。 私の質問はどのように私は私のコードを調整することができますので、唯一の1行は、別の画面に表示されるマイXML下のシートを異なるスクリーンサイズでサイズを調整するにはどうすればいいですか?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    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" 
    android:padding="0dp"> 
    <fragment 
     xmlns:map="http://schemas.android.com/apk/res-auto" 

     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.example.dell.drawroutes.MapsActivity" /> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/bottom_sheet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
     android:background="@android:color/white" 
     android:clipToPadding="true"> 

     <GridLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:paddingTop="@dimen/card_margin" 
      android:columnCount="3"> 

      <android.support.v7.widget.CardView 
       android:id="@+id/distancecard" 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/Card_View_Height" 
       android:layout_margin="@dimen/card_margin" 
       android:layout_columnSpan="1" 
       android:layout_column="0" 
       android:layout_gravity="fill" 
       android:layout_row="0" 
       android:layout_columnWeight="1"> 

       <LinearLayout 
        style="@style/Widget.CardContent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Info" 
         android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Hello World !" /> 

       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/Card_View_Height" 
       android:layout_marginBottom="@dimen/card_margin" 
       android:layout_marginLeft="@dimen/card_margin" 
       android:layout_marginRight="@dimen/card_margin" 
       android:layout_columnSpan="1" 
       android:layout_gravity="fill" 
       android:layout_column="1" 
       android:layout_row="0" 
       android:layout_columnWeight="1"> 

       <LinearLayout 
        style="@style/Widget.CardContent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Friends" 
         android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Hello World !" /> 

       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/Card_View_Height" 
       android:layout_marginBottom="@dimen/card_margin" 
       android:layout_marginLeft="@dimen/card_margin" 
       android:layout_marginRight="@dimen/card_margin" 
       android:layout_columnSpan="1" 
       android:layout_column="2" 
       android:layout_gravity="fill" 
       android:layout_row="0" 
       android:layout_columnWeight="1"> 

       <LinearLayout 
        style="@style/Widget.CardContent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Related" 
         android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Hello World !" /> 

       </LinearLayout> 

      </android.support.v7.widget.CardView> 
      <android.support.v7.widget.CardView 
       android:id="@+id/durationcard" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="@dimen/card_margin" 
       android:layout_marginLeft="@dimen/card_margin" 
       android:layout_marginRight="@dimen/card_margin" 
       android:layout_columnSpan="3" 
       android:layout_column="0" 
       android:layout_gravity="fill_horizontal" 
       android:layout_row="1"> 

       <LinearLayout 
        style="@style/Widget.CardContent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Duration" 
         android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Hello World !" /> 

       </LinearLayout> 

      </android.support.v7.widget.CardView> 


     </GridLayout> 
    </android.support.v4.widget.NestedScrollView> 

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

Javaコード

Emulator Image

Real device screenshot

のサイズ

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps2); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); View bottomSheet = findViewById(R.id.bottom_sheet); BottomSheetBehavior bottomSheetBehavior = bottomSheetBehavior.from(bottomSheet); bottomSheetBehavior.setPeekHeight(300); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 
+0

あなたが画面に基づいて動的にmapFragmentの高さを計算する必要がありますJavaコードのサイズ。 –

+0

どうすればいいですか?そして、これはどのように私は異なる画面サイズで表示するために1行だけを達成するのに役立ちますか? –

+0

map height =画面の高さ - 1行の高さ。この方法では最初は1行目のみを表示します –

答えて

0

あなたの一枚のカードが(あなたのレイアウトに応じて)の高さを持っています

@dimen/Card_View_Height 

setPeekHeight関数にこの値を渡します。

bottomSheetBehavior.setPeekHeight(getContext().getResources().getDimension(R.dimen.Card_View_Height)); 
+0

ありがとうございました:D it worked –

関連する問題