2017-05-18 6 views
1

もう1つのフラグメントが上部にあり、次に水平のLinearLayoutに2つの列totalgum = 3が含まれています。左の列は、TextViewとListViewを持つ垂直RelativeLayout(重み1)です。右は、TextViewとGridViewとボタンを持つ垂直LinearLayout(重み2)です。 Nougatでは間隔が劇的に変化しました。スタジオエミュレータと私自身のSamsung S7 Edgeの両方で。また、エミュレータはさまざまな画面レイアウトをレポートします。 Nexus 6P(1440 x 2560)の場合、API 23はLARGEを報告し、API 25はNORMALを報告します。私のSamsung s7 Edge(1440 x 2560も)はNORMALを報告し、7.0(API 24)を実行しています。Nougat 7.0 API 24および7.1 APIでAndroidレイアウトの間隔が変更されました25

API 24以降では、右のレイアウトは、重みが無視されているかのように、右端に対して非常にぴったりと絞られています。

API 23は問題なく動作します。私は同じエミュレータタイプ、6Pとちょうど異なるAPIを使用しました。 enter image description here

そして、ここではAPI 25は、次のようになります。:

enter image description here

そして、ここで私の断片である:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/fragment_course" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
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="com.hubbardsoftware.racetac.CourseActivityFragment" 
tools:showIn="@layout/activity_course"> 

<fragment 
    android:name="com.hubbardsoftware.racetac.TimerFragment" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    tools:layout="@layout/fragment_timer" /> 

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

    <RelativeLayout 
     android:id="@+id/course_part" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/course_course_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/title_course" 
      android:gravity="center" 
      android:textSize="@dimen/text_course_title" 
      android:textColor="#ff000000" 
      android:textStyle="bold" /> 

     <ListView 
      android:id="@+id/listview_course" 
      android:layout_below="@id/course_course_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center"/> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:layout_toEndOf="@id/course_part" 
     android:layout_toRightOf="@id/course_part" 
     android:layout_gravity="right" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/course_marks_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:gravity="center_horizontal" 
      android:text="@string/title_marks" 
      android:textSize="@dimen/text_course_title" 
      android:textColor="#ff000000" 
      android:textStyle="bold" /> 

     <GridView 
      android:id="@+id/gridview_course" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:numColumns="auto_fit" 
      android:stretchMode="columnWidth" /> 

     <Button 
      android:id="@+id/button_clear_course" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/button_rounded" 
      android:backgroundTint="@color/clearCourseButton" 
      android:text="@string/clear_all" 
      android:textSize="@dimen/text_course_clear" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/course_length" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:gravity="center_horizontal" 
      android:text="Length" 
      android:textSize="@dimen/text_course_length" 
      android:textColor="#ff000000" 
      android:textStyle="bold" /> 

    </LinearLayout> 

</LinearLayout> 

ここ

は、API 23は、次のようになります

なぜそのような変更について考えていますか?

((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) 

それがこのJavaコードの回避策は、解決APIで23

+0

追加情報:RelativeLayoutの幅を0dp(200dpから)に変更すると、API 24&25では正常に動作します。ただし、API 23では、上のように悪くはないものの、右の列​​が圧縮されます。私はrevを検出し、それを表示する前に手動で値を変更するJavaコードを追加する必要があるかもしれません。 –

+0

回避策が見つかりました。 XMLでこれを行うための「クリーン」な方法を誰かが知っているかどうかを知りたいのですが、私の「回答」を参照してください。 –

答えて

0

Configuration.SCREENLAYOUT_SIZE_LARGEに等しかったのに対し:それはAPI 24に真であり、かつこのサイズのデバイス25以下に関連してもよいように思えます誰かが知っていれば私はまだ適切なXMLソリューションが好きですが、問題です。上記のXMLをそのまま200dpのRelativeLayoutの幅で残しました。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) 
    { 
     RelativeLayout coursePart = (RelativeLayout) rootView.findViewById(R.id.course_part); 
     ViewGroup.LayoutParams params = coursePart.getLayoutParams(); 
     params.width = 0; 
    } 

両方新旧のAPIは、このコードで同じ表示:私はその後、私のフラグメントonCreateView方法で次のように行きました。

関連する問題