How to give scroll view on TextView using java for android - android

Hi my code can any any one tell me how to scroll text in textview for android.
physical = new TextView(this);
positionView.setTextView(getResources().getString(R.string.textviewp), 0,"Physical", physical, ImageType.TEXT_VIEW_GOAL);
physical.setId(R.id.physical);
physical.setTextColor(Color.BLACK);
physical.setTextSize(18);
physical.setTypeface(fonts);
physical.setBackgroundColor(Color.parseColor("#FFFFFF"));
physical.setOnClickListener(onClickListener);
physical.setOnLongClickListener(OnLongClickListener);
ScrollGoalRelativeLayout.addView(physical);

set the android:maxLines and android:scrollbars = "vertical" properties of textview in xml file in layout.
After that use the TexView.setMovementMethod(new ScrollingMovementMethod()) in your code.

Related

auto scroll in scrollview with speed

I want to auto-scroll lyrics on my app using ScrollView with speed control button. I have tried to animate the scrolling, but it didn't work.
For normal scrolling just set the
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.
Then use:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
in your code.

android textview set height does not work

I am trying to create a layout with nested linear layouts and textviews which are placed vertically in a linear layout. They are created programatically. While I can set the height of the linear layout using layout Params I am not able to do this for textview. Using Textview setLayoutParams or setHeight function provides no response. The text is always wrapped around the content (though this is no where mentioned by me in the code). Can someone help me fix this?
this code might help you:
LinearLayout.LayoutParams paramsLayoutExpire = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
TextView txtView=new TextView(this);
txtView.setLayoutParams(paramsTextViewExpire);
LayoutParams.MATCH_PARENT: Height
LayoutParams.WRAP_CONTENT: Width
I hope this might help
TextView textView = new TextView(this);
textView.setText("Hellow World");
textView.setHeight(prefered_height_in_pixel);
this.addView(textView)

How do i design scrollable text view in layout?

I'm not getting this "Scrollable Text View" part.. It messes up..
You don't need to use a ScrollView actually.
Just set the
android:maxLines = "a number"
android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.
Then use:
yourTextView.setMovementMethod(new ScrollingMovementMethod())
in your code.
it will scrolls automatically.

Formatting Dynamic Edittext Android

ANDROID
I have a layout defined in xml and have a static textview, edittext and checkboxes which are all formatted as below:
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="2"
android:singleLine="true"
android:textSize="14dp"
android:width="180dp"
I add textview, edittext and checkbox dynamically. I need the new added ones to have the same visual display as the ones already present(static ones) on the layout! Could someone guide or point me how to go about it?
You can add the layout by inflating each time you need textview, edittext and chekbox.This way your layout will have same look.Because you are reusing your static layout in xml.
See Layout Inflating for details
You have a layout with textview,edittext and checkbox.Now you will use the layout as a view.Like you said for each row you have to inflate the layout and add it to the row.So for every row you will have the copy of the layout.
TableLayout layout=(TableLayout)findViewById(R.id.tblLayout);
Now you can add the view after inflating the layout
View rowView = inflater.inflate(R.layout.row_layout, null, true);
TableRow tblrow=new TableRow(this);
tblRow.add(rowView);
layout.add(tblRow);
You can create any control Dynamic like this way.
Here i show for Edit Text same way you can do for others.
EditText et = new EditText(this);
et.setText("");
et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Use the following code for dynamic configurations about EditText.
EditText my_edit = (EditText) findViewById(R.id.my_edit);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.weight = 2.0f;
my_edit.setLayoutParams(params);
my_edit.setTextSize(20);
my_edit.setWidth(180);
my_edit.setSingleLine(true);
For this you must need LinearLayout as a parent of your EditText.
I hope this helps you somehow.
Thanks.

Dynamiclly add a textview using existing textview layout parameters

I am trying to add a TextView from the activity when a button has been pressed. I have found how to add a new textview from the activity, however instead of coding the required layout parameters is it possible to copy an existing textviews parameters (in the xml layout) to the new textview?
I have tried:
TextView tv1 = new TextView(this);
TextView tv2 = (TextView) findViewById(R.id.basetext);;
// its this line below which doesn't work
tv1.setLayoutParams(tv2.getLayoutParams());
But it doesn't copy any of the layout parameters...
Any ideas?
You can do One thing.
If you are trying to set just the Value of the Same TextValue every time and if the Layout properties of that TextView is same at all the time then follow below steps:
First Create the One Layout that only contain he TextView layout only with your appropriate properties. (Let name it as layout_textView.xml)
Now, do add that layout_textView.xml dynamically to your main view as per your requirement.
How it will Solve your issue.
If any query then let me know.
Did you call requestLayout() after adding the textview?

Categories

Resources