2013-09-27 2 views
0

// 앱이 어떻게 작동해야합니까? 안드로이드 응용 프로그램을 작성하려고합니다. 2 개의 카드 X 3 카드 격자 (행 x 열)에 배열 된 6 개의 '정보 카드'를 표시하려고합니다. 내 집에있는 뷰포트. 활동이 시작되면 사용자는 6 개의 카드가 격자 모양으로 배열 된 것을 볼 수 있습니다. 그들은 원래의 6 장의 카드가 화면 밖으로 미끄러지 게하고 다른 6 장의 카드가 화면 위로 미끄러지는 행동을 할 수 있습니다.Android 사용자 정의보기가 천천히 렌더링됩니다.

// 카드 세부 사항 카드 자체는 각 카드의 정보 필드가 동일하지만 각 카드마다 각 필드마다 다른 정보가 있습니다 (예 : 각 카드에 대해 textView가 있습니다. 카드의 이름을 표시하지만 각 카드의 텍스트보기에 다른 이름이 표시됨). 이를 달성하기 위해 카드의 XML 레이아웃을 부 풀린 다음 각 textView, imageView 등을 각 카드에 대한 사용자 정의 정보로 채우는 카드 클래스를 만들었습니다. 이 뷰는 Fragments의 뷰로 추가되어 화면에 표시된 각 카드는 실제로 Fragment이고 뷰 페이지 내부에있는 조각 인 2 X 3 그리드에 표시됩니다. 그래서, 나는 ViewPager를위한 페이지로 사용한 다른 그리드 Fragment에 배치 된 Fragments 카드를 가지고 있습니다. 또한 카드는 뒤집기가 가능하기 때문에 앞면과 뒷면이 있습니다. 단일 레이아웃 파일을 사용하여 카드 앞면과 뒷면을 만듭니다. 카드의 앞면 또는 뒷면을 보여주고 싶을 때 앞면 레이아웃이나 뒷면 레이아웃을 선택적으로 표시하거나 숨 깁니다.

// 문제 내 문제는 앱이 시작될 때 카드 렌더링을 기다리는 동안 갤럭시 탭 10.1 및 Nexus 7을 사용하여 6 - 10 초 지연이 발생한다는 것입니다. 모든 카드 데이터는 로컬 데이터이므로 웹 서비스가 데이터를 반환 할 때까지 기다리지 않고 데이터를 손에두고 사용할 준비가되었습니다. 지연 시간은 아마도 많은 레이아웃과 위젯으로 구성된이 카드를 렌더링해야한다는 사실 때문일 것으로 생각됩니다. 또한 런타임시에는 렌더링해야 할 카드의 수를 모를 수 있으므로 항상 카드 조각의 인스턴스를 프로그래밍 방식으로 생성합니다.

// 조사한 것 카드를 조각으로 만들려고 한 이유는 카드 조각을 간단한 조각으로 된 다른 조각으로 교체하기 위해서입니다. 렌더링 속도가 단순한 레이아웃을 가진 조각을 사용하여 허용 가능한 수준으로 증가한다는 것을 발견했습니다.

// 내 질문 카드를 사용하여 화면을 렌더링하는 데 걸리는 시간을 줄이기 위해 무엇을해야할지 모르겠습니다. 가능한 한 간단하게 카드 용 XML 레이아웃을 만들려고 노력하고 있습니다.하지만 어느 시점에서는 더 이상 XML 레이아웃을 디자인하지 않아도 단순화 할 수 없습니다. 내가보고있는 성능 저하를 보지 않고 위젯이 많은 레이아웃을 렌더링하는 것이 가능한지에 대한 제안을 찾고 있습니다. 복잡한 레이아웃을 렌더링하기위한 요령이나 트릭이 있습니까? 내 카드를 프로그래밍 방식으로 완전히 정의 할 수 있습니까 (XML 레이아웃 없음)? 당신이 볼 수있는 뻔뻔스런 오류가 있습니까?

도움을 주시면 감사하겠습니다. 감사! 카드 당신이 정말로 당신의 레이아웃을 검토 할 필요가 악의로

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <RelativeLayout 
     android:layout_width="257dp" 
     android:layout_height="343dp" 
     android:id="@+id/cardContainerRL" 
     android:layout_centerInParent="true"> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/cardFrontRL"> 

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

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/frontUpperRL" 
        android:layout_weight="1" 
        android:focusable="false" 
        android:background="@drawable/card_top_note"> 

        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="50dp" 
         android:id="@+id/frontHeader"> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="Waiting to be completed" 
          android:id="@+id/frontStatusTV" 
          android:layout_alignParentTop="false" 
          android:singleLine="false" 
          android:layout_centerInParent="true" 
          android:textSize="12dp"/> 

         <ImageView 
          android:layout_width="20dp" 
          android:layout_height="20dp" 
          android:id="@+id/frontStarIV" 
          android:src="@drawable/cool_star" 
          android:adjustViewBounds="true" 
          android:layout_toLeftOf="@+id/frontStatusTV" 
          android:layout_centerVertical="true" 
          android:longClickable="true"/> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="1" 
          android:id="@+id/numMessagesTV" 
          android:layout_alignParentTop="true" 
          android:layout_alignParentRight="true" 
          android:layout_marginRight="2dp"/> 
        </RelativeLayout> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Walk the Dogs Yo!" 
         android:id="@+id/frontTaskTV" 
         android:layout_below="@+id/frontHeader" 
         android:layout_marginTop="5dp" 
         android:layout_centerHorizontal="true" 
         android:textSize="22dp"/> 

       </RelativeLayout> 

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/frontLowerRL" 
        android:layout_weight="1" 
        android:focusableInTouchMode="true" 
        > 

        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:id="@+id/imageClip" 
         android:background="@drawable/card_bottom"> 
        </RelativeLayout> 

        <ImageView 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:id="@+id/cardImageIV" 
         android:layout_marginLeft="4dp" 
         android:layout_marginRight="4dp" 
         android:layout_marginBottom="4dp" 
         android:src="@drawable/bulldog" 
         android:adjustViewBounds="true" 
         android:scaleType="fitXY"/> 
       </RelativeLayout> 

      </LinearLayout> 

      <TextView 
       android:layout_width="77dp" 
       android:layout_height="77dp" 
       android:text="666" 
       android:id="@+id/cardPointsTV" 
       android:layout_centerInParent="true" 
       android:singleLine="true" 
       android:background="@drawable/points_circle" 
       android:gravity="center_vertical|center_horizontal" 
       android:textSize="24dp" 
       android:textStyle="bold"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Due on Sat. Nov 13" 
       android:id="@+id/frontDateTV" 
       android:layout_above="@+id/cardPointsTV" 
       android:layout_centerHorizontal="true" 
       android:textSize="15dp"/> 
     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:id="@+id/cardBackLL"> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/backUpper" 
       android:layout_weight=".65" 
       android:background="@drawable/card_top"> 

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="@dimen/back_header_height" 
        android:id="@+id/backHeader" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentRight="true"> 

        <ImageView 
         android:layout_width="@dimen/back_star_width" 
         android:layout_height="@dimen/back_star_width" 
         android:id="@+id/backStarIV" 
         android:layout_alignParentTop="false" 
         android:layout_alignParentLeft="false" 
         android:src="@drawable/cool_star" 
         android:scaleType="fitXY" 
         android:layout_marginLeft="@dimen/back_star_margin_left" 
         android:layout_centerVertical="true"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="To be completed" 
         android:id="@+id/backStatusTV" 
         android:layout_centerVertical="true" 
         android:singleLine="false" 
         android:textSize="@dimen/back_status_font_size" 
         android:layout_marginLeft="@dimen/card_back_detail_text_margin_left"/> 

        <LinearLayout 
         android:orientation="vertical" 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" 
         android:layout_alignParentRight="true" 
         android:layout_alignParentTop="false" 
         android:layout_alignParentBottom="false" 
         android:layout_marginRight="@dimen/card_back_points_container_margin_right"> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="fill_parent" 
          android:text="POINTS" 
          android:id="@+id/POINTS" 
          android:layout_alignParentRight="true" 
          android:textSize="@dimen/back_card_points_font_size" 
          android:layout_weight="1" 
          android:gravity="bottom"/> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="fill_parent" 
          android:text="666" 
          android:id="@+id/backPointsTV" 
          android:layout_alignParentRight="true" 
          android:textColor="@color/dark_gray" 
          android:layout_alignParentBottom="true" 
          android:textStyle="bold" 
          android:textSize="@dimen/back_card_point_value_font_size" 
          android:layout_weight="1" 
          android:gravity="top"/> 
        </LinearLayout> 

       </RelativeLayout> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Walk the Dogs Yo!" 
        android:id="@+id/backTaskTV" 
        android:layout_below="@+id/backHeader" 
        android:phoneNumber="true" 
        android:textSize="@dimen/card_back_taskname_font_size" 
        android:textIsSelectable="false" 
        android:layout_marginLeft="@dimen/card_back_detail_text_margin_left" 
        android:maxLines="2"/> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="DUE ON" 
        android:id="@+id/dueOnTV" 
        android:layout_alignLeft="@+id/backHeader" 
        android:layout_alignParentBottom="true" 
        android:textSize="12dp" 
        android:textIsSelectable="false" 
        android:layout_marginLeft="@dimen/card_back_detail_text_margin_left"/> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Sun. May 14" 
        android:id="@+id/backDateTV" 
        android:textSize="12dp" 
        android:textStyle="italic" 
        android:layout_toRightOf="@+id/dueOnTV" 
        android:layout_alignTop="@+id/dueOnTV" 
        android:layout_marginLeft="4dp" 
      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/backLower" 
       android:layout_weight=".35" 
       android:background="@drawable/card_bottom"> 

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="49dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentRight="true" 

        <ImageView 
         android:layout_width="@dimen/back_button_width" 
         android:layout_height="@dimen/back_button_height" 
         android:id="@+id/backArrowIV" 
         android:layout_alignParentLeft="true" 
         android:src="@drawable/btn_back" 
         android:layout_centerVertical="true" 
         android:layout_marginRight="@dimen/arrow_button_margin_right" 
         android:scaleType="fitXY"/> 

        <view 
         android:layout_width="@dimen/back_buttons_width" 
         android:layout_height="@dimen/back_buttons_height" 
         class="com.android.ui.widgets.ActionButton" 
         android:id="@+id/editButton" 
         android:layout_centerVertical="true" 
         android:layout_alignParentRight="true" 
         android:layout_marginRight="@dimen/send_button_margin_right"/> 

        <view 
         android:layout_width="@dimen/back_buttons_width" 
         android:layout_height="@dimen/back_buttons_height" 
         class="com.android.ui.widgets.ActionButton" 
         android:id="@+id/sendMessageButton" 
         android:layout_centerVertical="true" 
         android:layout_toLeftOf="@+id/editButton" 
         android:layout_marginRight="@dimen/edit_button_margin_right"/> 

       </RelativeLayout> 
      </RelativeLayout> 
     </LinearLayout> 

    </RelativeLayout> 

</RelativeLayout> 

답변

1

에 대한

// XML 레이아웃. 훨씬 더 복잡한보기를이 레이아웃보다 5 ~ 10 배 더 가벼운 레이아웃으로 만들 수 있습니다. 들 :

<RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
    <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
     <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
      <LinearLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
       <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
        <RelativeLayout"> <!--DISPATCH MEASURE LAYOUT DRAW --> 
         <TextView/> <!-- MEASURE LAYOUT DRAW --> 
         <ImageView/> <!-- MEASURE LAYOUT DRAW --> 
         <TextView/> <!-- MEASURE LAYOUT DRAW --> 
        </RelativeLayout> 
        <TextView/> <!-- MEASURE LAYOUT DRAW --> 
       </RelativeLayout> 
       <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
        <RelativeLayout> <!--DISPATCH MEASURE LAYOUT DRAW --> 
        </RelativeLayout> 
        <ImageView/> <!-- MEASURE LAYOUT DRAW --> 
       </RelativeLayout> 
      </LinearLayout> 
      <TextView/> <!-- MEASURE LAYOUT DRAW --> 
      <TextView/> <!-- MEASURE LAYOUT DRAW --> 
     </RelativeLayout> 
     <LinearLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
      <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
       <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW--> 
        <ImageView/> <!-- MEASURE LAYOUT DRAW --> 
        <TextView/> <!-- MEASURE LAYOUT DRAW --> 
        <LinearLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
         <TextView/> <!-- MEASURE LAYOUT DRAW --> 
         <TextView/> <!-- MEASURE LAYOUT DRAW --> 
        </LinearLayout> 
       </RelativeLayout> 
       <TextView /> <!-- MEASURE LAYOUT DRAW --> 
       <TextView /> <!-- MEASURE LAYOUT DRAW --> 
       <TextView /> <!-- MEASURE LAYOUT DRAW --> 
      </RelativeLayout> 
      <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
       <RelativeLayout> <!-- DISPATCH MEASURE LAYOUT DRAW --> 
        <ImageView /> <!-- MEASURE LAYOUT DRAW --> 
        <view /> <!-- MEASURE LAYOUT DRAW --> 
        <view /> <!-- MEASURE LAYOUT DRAW --> 
       </RelativeLayout> 
      </RelativeLayout> 
     </LinearLayout> 
    </RelativeLayout> 
</RelativeLayout> 

심지어이 레이아웃을 구문 분석하는 소형 기기에 시간이 좀 걸릴 것입니다. 그리고 이것은 창조를위한 것일 뿐이므로 터치 이벤트를 이와 같은 뷰 계층 구조로 파견하는 것에 대해 생각하고 싶지는 않습니다.

정말 가벼운 레이아웃으로 나올 수 없다면. 당신이 정말로 문제는 계층 구조하지 생각한다면,하지만 하나 날 믿어 -

건배, 샘.

출처 : Google 및 Android 개발 경험 년.

+0

중첩 된 레이아웃을 모두 없애고 모든 것을 두 개의 서로 다른 relativelayouts에 맞게 관리했습니다. 하나는 카드의 앞면 용이고 다른 하나는 뒷면 용입니다. 각 상대 레이아웃 내에서 나는 dimen 파일에 설정 한 dps를 사용하여 모든 UI 요소를 배치 할 수있었습니다. 이것은 뷰 계층 구조를 실제로 평평하게 만들고 성능을 상당히 향상 시켰습니다. 감사! – neonDion

관련 문제