2017-05-15 1 views
-1

enter image description here화면 크기에 따라 동적으로 버튼의 크기를 조정할 수 있습니까?

나는 테이블 레이아웃에 버튼이 있습니다. 여기

TableLayout tblHotels=(TableLayout) findViewById(R.id.tblLayout); 
     if(hotels != null){ 
      int index=0; 
      for (int i=0; i<(hotels.length/2); i++) { 
       TableRow tblRow=new TableRow(getApplicationContext()); 
       tblHotels.addView(tblRow); 
       tblRow.setLayoutParams(new TableLayout.LayoutParams(
         TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT)); 
       for (int j=0;j<2; j++) 
       { 
        tblRow.addView(hotels[index]); 
        hotels[index].setLayoutParams(new TableRow.LayoutParams(
          TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT, 1.0F)); 
        hotels[index].setOnClickListener(this); 
        index++; 
       } 
      } 
     } 

테이블 레이아웃에서 동적으로 버튼을 넣어하지만 내가 같은 폭과 조금 더 높이 내 버튼을 원하는 화면으로 나타납니다. 내가 어떻게 해? 내 xmlfile이 지금과 같습니다.

`<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.arzucaki.sherwoodhotels.Hotels" 
    android:weightSum="1" 
    > 


    <TableLayout 
     android:id="@+id/tblLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="0.6" 
     android:gravity="bottom" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true"> 


    </TableLayout> 




</RelativeLayout>` 
+0

경우, 테이블 레이아웃이 제대로 표시되지 않습니다. list/recyclerview/gridview 레이아웃을 사용하는 것이 좋습니다. –

답변

0
당신은 가서 XML 파일의 테이블 행을 만들고 dimens.xml 파일에서 테이블 행의 높이를 정의 할 수 있습니다

:

<TableRow 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/table_row_height"> 

     <TextView 
      android:text="Time" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:layout_column="1" /> 

     <TextView 
      android:text="Time" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:layout_column="2" /> 
    </TableRow> 

추가 : 여기

은 샘플 표현입니다 각 폴더에서 지원할 모든 해상도에 대한 dimens.xml 파일 예. 값, 값-w820dp 등 그냥이 폴더 내에서 dimens라는 이름으로 새 파일을 생성하고이처럼 값을 선언합니다

<resources> 
<!-- Table Row height --> 
<dimen name="table_row_height">16dp</dimen> 

이 값은 값-w820dp에서 다른 파일에 더 높을 것 아마도 다음과 같이 귀하의 요구 사항에 따라 : (100) 호텔 (더 의미)가

<resources> 
<!-- Table Row height --> 
<dimen name="table_row_height">24dp</dimen> 

+0

ok 기다리려고 애 쓰고 있습니다. – arzucaki

+0

모든 버튼이 화면에 1의 무게를 채 웁니다. İ 다른 화면 크기의 모든 기기에서 동일한 비율로 화면을 볼 수있는 방법을 알고 싶습니다. – arzucaki

+0

이 경우 xml 파일에서 테이블 행을 정의하고 mdpi, hdpi, xhdpi, xxhdpi 및 xxxhdpi와 같은 다양한 장치 해상도에 해당하는 dimens 파일의 크기 크기를 제공해야합니다. 또한 match_parent를 wrap_content로 변경할 수 있습니다 일부 패딩을 제공합니다. 이렇게하면 컨트롤이 전체 화면을 차지하지 않고 패딩을 일부 제공합니다. 그러나 장치 해상도에 따라 크기가 달라야한다는 요구 사항에 따라 파일 크기를 조정해야합니다. – Saurabh7474

관련 문제