2016-12-06 86 views
0

如何在滾動視圖的下方添加向下箭頭按鈕,以便在按下滾動視圖時將其展開爲height.on,然後再按下它縮小到原始高度。我只想要在ScrollView中顯示一個小內容,按下按鈕顯示更多內容。Android滾動查看擴大和縮小

我該如何做到這一點?請幫忙。 感謝advnc

這裏是我的滾動視圖

 <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_marginBottom="@dimen/_5sdp" 
     android:layout_height="@dimen/_120sdp" 
     > 

     <TableLayout 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/tl" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".customer.database.OrderNew_Activity" 
      android:layout_weight="2" 
      > 



     </TableLayout> 

    </ScrollView> 

我想在按下按鈕

+1

然後定義你的滾動視圖的高度田間,把一些ImageButton的ANE時按下按鈕滾動型化妝高度WRAP_CONTENT –

回答

0

下面添加滾動視圖按鈕顯示tablelayout和顯示器的休息小部分。

在您的活動中添加全局布爾變量來檢查scrollview是否展開。

boolean exapanded = false; 

在按鈕的onclick聽衆做以下

if(expanded){ 
scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,100)); 
expanded = false; 
} 
else{ 
scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
expanded = true; 
} 
+0

感謝...現在的作品完美 – c0der

1

在這裏,我試圖解決您的問題。

你只需要以下內容添加到您的的build.gradle文件:

compile 'com.ms-square:expandableTextView:0.1.4' 

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.expandabletextview.MainActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <com.ms.square.android.expandabletextview.ExpandableTextView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/expand_text_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      expandableTextView:animDuration="500" 
      expandableTextView:maxCollapsedLines="4"> 

      <TextView 
       android:id="@id/expandable_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:textColor="#666666" 
       android:textSize="16dp" /> 

      <ImageButton 
       android:id="@id/expand_collapse" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right|bottom" 
       android:background="@android:color/transparent" 
       android:padding="16dp" /> 
     </com.ms.square.android.expandabletextview.ExpandableTextView> 
    </ScrollView> 
</RelativeLayout> 

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // sample code snippet to set the text content on the ExpandableTextView 
     ExpandableTextView expTv1 = (ExpandableTextView) findViewById(R.id.expand_text_view); 

     // IMPORTANT - call setText on the ExpandableTextView to set the text content to display 
     expTv1.setText(getString(R.string.dummy_text1)); 
    } 
} 

string.xml

<resources> 
    <string name="dummy_text1">Hellooooooooooooooo This is dummy text. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</string> 
</resources>