-1

나는 100 개의 버튼이있는 앱을 개발 중입니다. 그리고 모든 버튼을 화면에 넣고 싶습니다. 내가 가지고있는 문제 내부의 모든 버튼과 함께 GridLayout을 사용하고 있습니다. 버튼이 스크린에서 빠져 나가는 것입니다.그리드 레이아웃의 내용을 화면 내에 유지하는 방법

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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/content_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    android:layout_column="1"> 

<GridLayout 
    android:id="@+id/GridLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:columnCount="6" 
    android:rowCount="17" 
    android:orientation="vertical"> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     app:srcCompat="@drawable/numero_1" 
     android:id="@+id/button1"/> 

I가 가지고있는 질문 :이 가능 할

This is the problem that I am having

코드인가? 그리고 이것이 최선의 방법입니까?

이미지의 크기를 변경 한 다른 테스트를 수행했습니다. 결과는 내가 다른 크기의 이미지와 헤더

결과를 예상 것이 아니다

Image with other size

당신은 행의 버튼이 화면 안에있는 두 번째 이미지하지만 버튼의 위치에서 볼 수 있듯이 좋아요, 행의 마지막 버튼과 화면 끝 사이에 많은 공간이 있습니다.

내가 찾고있는 해결책은 화면 크기가 다른 경우 단추가 화면 밖으로 나오지 못하게하고 단추와 가장자리 사이의 공간 크기를 자동으로 조정하는 레이아웃을 사용하는 것입니다 레이아웃은 자동으로 화면의 크기에 맞춰집니다.

답변

0

나는 그것이 가능하지 않다고 생각합니다. 하나의 수평선에 6 개의 수직 LinearLayouts를 사용하고, 내부에는 1을 사용하도록 제안합니다. 나는 그것이 가장 최적화 된 방법이 아니라는 것을 알고 있지만, 가장 쉽습니다. 또 다른 방법은 GridLayout을 유지하고 이미지 크기를 계산하고 Java 코드에서 크기를 설정하는 것입니다.

관련 문제