2017-03-24 2 views
-1

Ich habe ein Problem mit meinem TicTacToe. Das Board muss ein 4x4-Quadrat sein und Elemente müssen ebenfalls Quadrate sein. Ein GridLayout wurde angewendet. Das Problem ist, dass auf kleinen Bildschirmen (auch im Querformat) das Board vom Bildschirm verschwindet.Ansichten fahren vom Bildschirm (Android)

Hier ist, wie es aussieht:

landscape

small screen

Hier Code ist:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout     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:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.kasia.tictactoe.BoardActivity" 
android:id="@+id/parent"> 



<android.support.constraint.ConstraintLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintBottom_toBottomOf="@id/parent" 
    app:layout_constraintTop_toTopOf="@id/parent" 
    app:layout_constraintStart_toStartOf="@id/parent" 
    app:layout_constraintEnd_toEndOf="@id/parent" 
    android:id="@+id/boardLayout" 

    > 

<com.example.kasia.tictactoe.MyGridLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:rowCount="4" 
    android:columnCount="4" 
    android:id="@+id/gridLayout" 
    android:layout_centerInParent="true" 
    app:layout_constraintBottom_toBottomOf="@id/boardLayout" 
    app:layout_constraintTop_toTopOf="@id/boardLayout" 
    app:layout_constraintRight_toRightOf="@id/boardLayout" 
    app:layout_constraintLeft_toLeftOf="@id/boardLayout" 



    > 


    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

    </com.example.kasia.tictactoe.GridViewButton> 

    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:layout_gravity="fill_horizontal" 
     android:scaleType="centerCrop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </com.example.kasia.tictactoe.GridViewButton> 

    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </com.example.kasia.tictactoe.GridViewButton> 



    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </com.example.kasia.tictactoe.GridViewButton> 


    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 


     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 



    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 

    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:layout_gravity="fill_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 
     android:scaleType="centerCrop" 
     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill_horizontal" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill_horizontal" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 
    <com.example.kasia.tictactoe.GridViewButton xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_rowWeight="1" 
     android:layout_columnWeight="1" 
     android:scaleType="centerCrop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill_horizontal" 

     > 
    </com.example.kasia.tictactoe.GridViewButton> 

</com.example.kasia.tictactoe.MyGridLayout> 
</android.support.constraint.ConstraintLayout> 

public class MyGridLayout extends GridLayout { 
public MyGridLayout(Context context) { 
    super(context); 
} 

public MyGridLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public MyGridLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

public MyGridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super(context, attrs, defStyleAttr, defStyleRes); 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec,widthMeasureSpec); 
} 

}

public class GridViewButton extends Button { 


public GridViewButton(Context context) { 
    super(context); 
} 

public GridViewButton(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public GridViewButton(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

public GridViewButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super(context, attrs, defStyleAttr, defStyleRes); 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec, widthMeasureSpec); 
} 

}

ich irgendwelche Tipps zu schätzen wissen würde ...

+0

Verwendung gridview lösen Ihr probelm – g7pro

Antwort

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="4" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 

    <ImageButton 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:src="@mipmap/ic_launcher_main" /> 
</LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:weightSum="4" > 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_main" /> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_main" /> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_main" /> 
     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_main" /> 
    </LinearLayout> 

</LinearLayout> 
Verwandte Themen