2017-11-22 3 views
1

의 2 행은 내가 위의 두 배로하고자하는 다음과 같은 구조의 4 텍스트 뷰 (2 개 라벨, 데이터 2)Android 선형 레이아웃. 2

Label Label 
Data  Data 

와 선형 레이아웃을 가지고 있지만 나는 큰 어려움에 봉착했습니다. 욕망 이것은 내가 지금까지 무엇을위한 코드입니다

Label Label 
Data  Data 
Label Label 
Data  Data 

입니다. 더 많은 텍스트보기를 추가하면 위치가 표시됩니다.

<LinearLayout 
    android:id="@+id/linearLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/temperatureLabel" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:orientation="horizontal" 
    android:weightSum="100" android:baselineAligned="false"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/label" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="@string/label" 
      android:textColor="#80ffffff" /> 

     <TextView 
      android:id="@+id/data" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="@string/data" 
      android:textColor="@android:color/white" 
      android:textSize="24sp" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/Label" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="@string/label" 
      android:textColor="#80ffffff" /> 

     <TextView 
      android:id="@+id/data" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="@string/data" 
      android:textColor="@android:color/white" 
      android:textSize="24sp" /> 
    </LinearLayout> 
</LinearLayout> 
+0

원하는 스크린 샷을 넣을 수 있습니까? – diegoveloper

+0

이전과 이후에 원하는 코드는 무엇입니까? 전후에 어떤 모습 이었습니까? –

+0

구조 업데이트 된 ID가 –

답변

2

두 배로 늘리거나 레이아웃과 같은 테이블을 사용하려는 경우. gridLayout을 사용하여 문제를 해결할 수 있습니다.

예 :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:stretchMode="columnWidth" 
    app:columnCount="2" 
    app:rowCount="2"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical" 
     app:layout_column="0" 
     app:layout_columnWeight="1" 
     app:layout_row="0"> 

     <TextView 
      android:id="@+id/label" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="abel" 
      android:textColor="@android:color/holo_blue_bright" /> 

     <TextView 
      android:id="@+id/data" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="data" 
      android:textColor="@android:color/black" 
      android:textSize="24sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical" 
     app:layout_column="1" 
     app:layout_columnWeight="1" 
     app:layout_row="0"> 

     <TextView 
      android:id="@+id/label1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="abel" 
      android:textColor="@android:color/holo_blue_bright" /> 

     <TextView 
      android:id="@+id/data1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="data" 
      android:textColor="@android:color/black" 
      android:textSize="24sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical" 
     app:layout_column="0" 
     app:layout_columnWeight="1" 
     app:layout_row="1"> 

     <TextView 
      android:id="@+id/label2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="abel" 
      android:textColor="@android:color/holo_blue_bright" /> 

     <TextView 
      android:id="@+id/data2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="data" 
      android:textColor="@android:color/black" 
      android:textSize="24sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="50" 
     android:orientation="vertical" 
     app:layout_column="1" 
     app:layout_columnWeight="1" 
     app:layout_row="1"> 

     <TextView 
      android:id="@+id/label3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="abel" 
      android:textColor="@android:color/holo_blue_bright" /> 

     <TextView 
      android:id="@+id/data3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="data" 
      android:textColor="@android:color/black" 
      android:textSize="24sp" /> 
    </LinearLayout> 
</android.support.v7.widget.GridLayout> </FrameLayout> 
+0

작동하지 않습니다. 안드로이드는 레이아웃 행과 관련된 오류를 모두 제공합니다 –

+0

게시 한 코드에 닫는 태그가 없습니다. 다시해볼 수 있을까요? 나는 그것을 테스트했고 여기에서 잘 작동한다. –

+0

[link] (https://imgur.com/a/SSItU) [link] –

0

좋은보기 레이아웃을 디자인 해 보겠습니다.

나는 당신이 당신의 LinearLayout을 반복하려고하는 것을 볼 수 있기 때문에 나는이 행동에 대한 좋은 해결책을 제시한다. 당신이 ListView에 또는 RecycleView를 사용하는 경우

당신은 당신의 레이아웃을 반복하고 설계가 복잡하게 할 필요가 없습니다.

의 ListView 또는 RecycleView에 대한 ArrayAdapter와를 작성하고 복잡하지 않고 빨리 당신의 반복 물건을 올려.

ListView에 몇 가지 문제가 있으며이 목록을 만드는 방법에 대해 잘 모르면이 질문에 대한 내 게시물을 볼 수 있습니다. link

행운을 빕니다.

+1

은 매우 사실입니다.이 특별한 경우에는 TS가 RecyclerView 용 GridLayoutManager를 사용해야하므로 항목 뷰는 Label 및 Data로 구성됩니다. –

+0

@ViktorYakunin 제 답변을 수정하십시오. 추가 정보 –

관련 문제