如何将静态expandabletextview设置为动态expandaletextview

时间:2015-04-02 06:02:22

标签: android

我在这个例子中创建了一个静态expandaletextview,我使用了两个Textview和两个ImageButton,所以现在我如何使这个动态可扩展..任何人都可以帮助我,因为我是非常新的android ...以下是我的完整静态源代码提前感谢

MainActivity class

package com.example.atextalignment;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;


public class MainActivity extends Activity {
     TextView descText;
     ImageButton show, hide;

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

      descText = (TextView) findViewById(R.id.description_text);
      show = (ImageButton) findViewById(R.id.show);
      show.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        System.out.println("Show button");
        show.setVisibility(View.INVISIBLE);
        hide.setVisibility(View.VISIBLE);
        descText.setMaxLines(Integer.MAX_VALUE);

       }
      });
      hide = (ImageButton) findViewById(R.id.hide);
      hide.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        System.out.println("Hide button");
        hide.setVisibility(View.INVISIBLE);
        show.setVisibility(View.VISIBLE);
        descText.setMaxLines(5);

       }
      });

     }

    }

my Xml layout

<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"
    tools:context="com.example.atextalignment.Second" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <TextView
        android:id="@+id/description_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:maxLines="5"
        android:text="@string/desc_content" />

    <ImageButton
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/description_text"
        android:background="@android:color/transparent"
        android:clickable="true"
        android:src="@drawable/ic_launcher"/>

    <ImageButton
        android:id="@+id/hide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/description_text"
        android:clickable="true"
        android:src="@drawable/ic_launcher"
        android:visibility="invisible" />

</RelativeLayout>

String.xml

<string name="desc_content">     Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It\'s the largest installed base of any mobile platform and growing fast—every day another million users power up their Android devices for the first time and start looking for apps, games, and other digital content.

Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.
</string>

0 个答案:

没有答案