Wednesday, 23 May 2012

How to scroll TextView in Android ?


Layout:

Set the
android:maxLines = "ANY INTEGER VALUE"

android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.  
<TextView
    android:id="@+id/myTextview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    android:maxLines="3"
    android:scrollbars="vertical"
    android:textColor="#000000"
    >
</TextView>


And in the code use: 

TextView textView = (TextView)findViewById(R.id.myTextView);
textView.setMovementMethod(new ScrollingMovementMethod());

Saturday, 19 May 2012

Android Expandable list view move group icon indicator to right

The setIndicatorBounds(int left, int right) is used to set the indicator bounds for the group view of an expandable list view.



DisplayMetrics metrics;
int width;
ExpandableListView expList;
       metrics = new DisplayMetrics();
       getWindowManager().getDefaultDisplay().getMetrics(metrics);
       width = metrics.widthPixels;
  //this code for adjusting the group indicator into                              right side of the view
expList.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10));
expList.setAdapter(new ExpAdapter(this));
public int GetDipsFromPixel(float pixels)
    {
     // Get the screen's density scale
     final float scale = getResources().getDisplayMetrics().density;
     // Convert the dps to pixels, based on density scale
     return (int) (pixels * scale + 0.5f);
    }