2015-01-02 1 views
0

TextView (이 예제에서는 7 개)의 난수가있는 내부에 LinearLayout이 화면의 전체 너비를 덮고 있습니다. 나는 모두 TextView이 같은 크기이므로, 각각에 android:layout_weight="1"이라는 속성을 넣었습니다.TextView가 부모 LinearLayout의 크기를 조정하는 것을 방지하려면 - Android

enter image description here

을하지만 각 TextView에 해당하는 텍스트를 추가 할 때, Textview 변화의 크기, 무게를 유지하고 LinearLayout 크기를 조정할 수 없습니다 :

텍스트 뷰의 모든 텍스트가없는 잘 작동

enter image description here

이 내 활동의 디자인의 일부에 불과합니다, 그래서 그 자체에 대한 새로운 XML에 재현 오류가 지속되면 e. 그리고 나는 LinearLayoutHorizontalScrollView

의 내부에있는 경우는 그렇지 않은 경우, 내가 예상 결과를 얻을 발생하는 것으로 나타났습니다 :

enter image description here

내 XML :

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal"> 

     <TextView 
      android:singleLine="true" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

     <TextView 
      android:singleLine="true" 
      android:layout_marginLeft="1dp" 
      android:text="LONG TEXT" 
      android:layout_marginBottom="1dp" 
      android:layout_marginTop="1dp" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:background="#009FDC" 
      android:gravity="center" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#fff" 
      android:textStyle="bold" 
      android:typeface="serif" /> 

    </LinearLayout> 
</HorizontalScrollView> 

누구든지이 문제를 해결하는 방법을 알고 있습니까? 미리 감사드립니다.

+0

설정을하여 높이와 너비 동적으로 textView합니다. –

+0

TextView에 텍스트 크기 속성을 설정합니다. – chain

+0

view를 스크롤하여 'horizontalScrollView'안에 뷰를 두는 이유는 무엇입니까? –

답변

1

을 보자

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:fillViewport="true" > 

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXTTTTTTTTTTTTTTTTTTTTTTTTTT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="1dp" 
     android:layout_marginLeft="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_weight="1" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 
</LinearLayout> 
</HorizontalScrollView> 

enter image description here

+0

나는 이것을 시도하고 탁월한 작업을하지만, 어떻게 각 TextView에 minWidth를 설정할 수 있습니까? 나는 그 일을 할 수 없다. –

+0

너는 minwidth를 설정하고 싶니? –

+0

태블릿을 가로로 배치하면 각 TextView의 크기가 좋아 보인다 그러나 세로 모드로 전환하면 각 TextView가 너무 작아서 최소 너비를 추가하고 내용을 스크롤합니다. –

0

나는 당신의 XML을 조금 바꿨다.

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

    <TableLayout 
     android:id="@+id/table_dashboared" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:stretchColumns="1" > 

     <TableRow 
      android:id="@+id/tablerow_header" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:weightSum="7" > 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textSize="12sp" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="1dp" 
       android:layout_weight="1" 
       android:background="#009FDC" 
       android:gravity="center" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="LONG TEXT" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#fff" 
       android:textStyle="bold" 
       android:typeface="serif" /> 
     </TableRow> 
    </TableLayout> 

</HorizontalScrollView> 
+0

android 추가 : weightSum = 아무런 차이가 없지만 도움을 주셔서 감사합니다. –

+0

너비가 모든 textview가 fill_parent 여야합니다. – Praveen

+0

동일합니다. 차이가 없습니다. –

0

이 코드 시도 내가 테이블 레이아웃과 노력이 시도이 시도하고 결과를 알려

<HorizontalScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true"> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="7"> 

    <TextView 
     android:singleLine="true" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <TextView 
     android:singleLine="true" 
     android:layout_marginLeft="1dp" 
     android:text="LONG TEXT" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:background="#009FDC" 
     android:gravity="center" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

</LinearLayout> 

관련 문제