2

TextViews 및 EditTexts가있는 TableLayout이 필요하며 크로스 워드 퍼즐과 같아야합니다.TableLayout 행의 TextView 및 EditText에 동일한 높이를 설정 하시겠습니까?

나는 LinearLayout, width=0dp and weight=1,으로이 테스트를했지만 내가 원하는처럼이 일을하지 않았다. 그런 다음 TableLayout을 사용하여 테스트 해 보았습니다. 솔루션에 가깝다고 생각합니다. XML이나 Java에서 높이와 너비를 테스트했지만 작동하지 않았습니다. 내 문제는 이제 모든 TextViews가 EditText보다 더 얇아서 왜 어떻게 보이게 할 수 있는지 모르겠습니다.

XML-파일 :

<!-- activity_sraetsel_main.xml --> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/table" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" >   
</TableLayout> 

<!-- activity_sraetsel_row.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/tableRow" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:gravity="center_horizontal"> 
</TableRow> 

<!-- activity_sraetsel_edittext.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
     android:background="@drawable/cell_border" 
     android:id="@+id/textView" 
     android:inputType="textCapCharacters" 
     android:gravity="center_horizontal" 
     android:maxLength="1"> 
</EditText> 

<!-- activity_sraetsel_textview.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:background="@drawable/cell_border" 
     android:id="@+id/textView" 
     android:textSize="6.5sp" 
     android:singleLine = "false" > 
</TextView> 

<!-- cell_border.xml --> 
<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#FFFFFF"/> 
<stroke android:width="1dp" android:color="#515151"/> 
<padding android:left="10dp" android:top="5dp" 
android:right="10dp" android:bottom="5dp" /> 
</shape> 

및 자바 부분, 내가 모두 함께 넣어 :

TableLayout table = (TableLayout) this.findViewById(R.id.table); 
for (int y = 0; y < hoehe; y++) { 
    // Inflate your row "template" and fill out the fields. 
    TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.activity_sraetsel_row, null); 
    for (int x = 0; x < breite; x++) { 
     if (raetsel[y][x].startsWith(",", 1)) { 
      EditText eText = (EditText) LayoutInflater.from(this).inflate(R.layout.activity_sraetsel_edittext, null); 
      if (!(raetsel[y][x].startsWith("a"))) { 
       eText.setText(raetsel[y][x].substring(0, 1)); 
      } //if 
      eText.setWidth(60); 
      eText.setHeight(60); 
      row.addView(eText); 
      Log.d(TAG, "SRaetselMain, AntwortFeld erstellt"); 
     } else { 
      TextView vText = (TextView) LayoutInflater.from(this).inflate(R.layout.activity_sraetsel_textview, null); 
      vText.setText(raetsel[y][x].substring(0, raetsel[y][x].indexOf("|"))); 
      vText.setWidth(60); 
      vText.setHeight(60); 
      row.addView(vText); 
      Log.d(TAG, "SRaetselMain, FrageFeld erstellt"); 
     } //if 
    } //for 
    table.addView(row); 
} //for 

table.requestLayout(); 

그리고 마지막으로 그것은처럼 보이는 방법 :

EDIT1 : XML 형식의 TextView에 android:layout_height="match_parent"을 사용하고 setHeight()를 사용하지 않는 경우 활동에서 텍스트 뷰 :

EDIT2

http://i.stack.imgur.com/btzj4.png

: android:layout_weight="1"android:layout_height="0dp" 그것이 지금은 TextViews없이 만 글고 치기로 테스트했습니다, 나는 것을 발견

EDIT1

같은 동일 보인다 문제는 textSize입니다. android:textSize="6.5sp" 옵션없이 TextView를 만들면 작동합니다. 그러나 텍스트가 크고 불행히도 나는이 텍스트가 작게 필요합니다.

EDIT3 : 내가있는 LinearLayout과 두 TextViews와 함께이 시도했습니다 . 나는이 두보기가 같은 높이에 있다는 것을 어떻게 바꿀 수 있는지 정말로 모른다.

http://i.stack.imgur.com/wIENf.png

이 문제에 대해 도움을 주셔서 감사합니다. XML에서 TextView에 대한

+0

스크린 샷 이미지 링크가 작동하지 않습니다. –

+0

고마워요! 이제 작동합니다. – SirArt

답변

2

답변 :

문제는 이것으로 해결된다 : android:baselineAligned="false" 이 XML에 줄을 넣고 작동!

<!-- activity_sraetsel_row.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableRow" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:gravity="center_horizontal" 
    android:baselineAligned="false"> 
</TableRow> 

감사합니다.

0

사용 android:layout_height="match_parent"ActivityTextViewsetHeight()를 제거합니다. 수동으로 크기를 EditText으로 설정 했으므로 변경하지 않아도됩니다. 이렇게함으로써 TextViewheight을위한 모든 공간을 차지할 것입니다.

편집

<!-- activity_sraetsel_edittext.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
     android:background="@drawable/cell_border" 
     android:id="@+id/textView" 
     android:inputType="textCapCharacters" 
     android:gravity="center_horizontal" 
     android:layout_width="60dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:maxLength="1"> 
</EditText> 

<!-- activity_sraetsel_textview.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:background="@drawable/cell_border" 
     android:id="@+id/textView" 
     android:textSize="6.5sp" 
     android:layout_width="60dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:singleLine = "false" > 
</TextView> 

10dplayout_weightlayout_height을 설정하십시오.

당신은 다음 layout_weight 도울 수 모두 View의의 같은 높이를합니다.내 자신의 질문에

+0

도움을 주셔서 대단히 감사합니다! 불행히도 TextView는 사각형이 아닙니다. 질문에 대한 링크를 새 스크린 샷과 연결합니다. – SirArt

+0

나는 이것을 시도했지만, 무엇이 잘못되었는지 이해하지 못합니다. 저는 XML을'android : layout_width = "60dp"'옵션으로 복사/붙여 넣었습니다. 그러나 셀은 그 안의 텍스트만큼 너비가 있습니다. 이제 TextViews 및 EditText 만 사용하여 테스트했는데 문제는 textSize라는 것을 알았습니다. TextView를'android : textSize = "6.5sp"옵션없이 만들면 작동합니다. 하지만 불행히도 나는이 텍스트가 작게 필요합니다. – SirArt

+0

텍스트 크기가 작 으면'android : textAppearance = "? android : attr/textAppearanceSmall"' – Krrishnaaaa

관련 문제