2012-07-03 26 views
17

Tôi muốn triển khai chế độ xem có thể thu gọn, chính xác như chế độ xem từ thị trường Google Play. Nó hiển thị một số hàng từ nội dung và một mũi tên và nhấn vào mũi tên để hiển thị toàn bộ nội dung. Điều này có được thực hiện với ExpandableListView hoặc có giải pháp nào khác không?Tôi làm cách nào để triển khai chế độ xem có thể thu gọn giống như chế độ xem từ Google Play?

Ảnh chụp màn hình được đính kèm với làm nổi bật những gì tôi đang tìm kiếm. Cảm ơn. enter image description here

+1

này có thể giúp: http://stackoverflow.com/questions/5165682/how-to-implement-expandable-panels-in-android – 0gravity

+0

Có , điều này giúp một chút, vì nó thực hiện những gì tôi đang tìm kiếm, nhưng tôi đã hy vọng rằng nó là một giải pháp dễ dàng hơn so với một bố trí tùy chỉnh ... –

Trả lời

29

Có một cách đơn giản hơn:

 final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content); 
     final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all); 
     showAll.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       showAll.setVisibility(View.INVISIBLE); 

       descriptionText.setMaxLines(Integer.MAX_VALUE); 
      } 
     }); 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:id="@+id/detail_description_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

     <TextView 
      android:id="@+id/detail_description_content" 
      android:maxLines="5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/detail_read_all" 
      android:clickable="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</ScrollView> 

Phần quan trọng là Maxlines và scrollview. Điều này không cung cấp cho một hình ảnh động chậm (đó sẽ là một giá thầu phức tạp hơn) nhưng một hiệu ứng ngay lập tức mở.

+0

Đó là tuyệt vời! –

+0

Người đàn ông Awsome, hoạt động như một sự quyến rũ. –

1

Xin lỗi tiếng anh kinh khủng của tôi.

Dựa trên Warpzip phản ứng

res/values/strings.xml 
... 
... 
<string name="str_more"><![CDATA[<p><b>This is the header</b><u>(see more ..)</u>]]></string> 
<string name="str_less"><![CDATA[<p><b>This is the header</b><u>(less ..)</u>]]></string> 
<string name="str_details"><![CDATA[<p>A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.</p>]]></string> 
... 
... 

Trong layoutIn bố trí của chúng tôi, chúng tôi có thể bao gồm một scrollview với một LinearLayout dọc (hoặc với một chút công việc một RelativeLayout). Trong những:

<TextView 
      android:id="@+id/txtvw_header" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:text="@string/str_more" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/txtvw_detail" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/txtvw_tituloEntreTodos" 
      android:text="@string/str_details" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

Cuối cùng Hoạt động của chúng tôi

view = inflater.inflate(R.layout.f_entretodos, container, false); 
     info = (TextView) view.findViewById(R.id.txtvw_header); 
     fullinfo = (TextView) view.findViewById(R.id.txtvw_detail); 
     info.setText(Html.fromHtml(getString(R.string.str_more))); 
     fullinfo.setText(Html.fromHtml(getString(R.string.str_detail))); 
     fullinfo.setVisibility(View.GONE); 
     info.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if (fullinfo.isShown()){ 
        fullinfo.setVisibility(View.GONE); 
        info.setText(Html.fromHtml(getString(R.string.str_more))); 
       }else{ 
        fullinfo.setVisibility(View.VISIBLE); 
        info.setText(Html.fromHtml(getString(R.string.str_less))); 
       } 
      } 

     }); 
Các vấn đề liên quan