Scrollview doesn't show scrollbar - android

my Android TextView xml is very simple like below, I used style ScrollView but it won't show scrollbar, even when the text is exceeding the bottom and there is no way for me to see what's beyond. How to enable the scrollbar please?
I think "match_parent" has issue but don't know how to fix. Thanks!
<?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:orientation="vertical"
android:background="#ffffff">
<TextView
android:id="#+id/textResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonRecord"
android:layout_marginTop="16dp"
android:background="#drawable/back"
android:editable="true"
android:height="150dp"
android:text=""
android:enabled="false"
android:scrollbars="vertical"
style="#android:style/Widget.ScrollView"
android:layout_alignRight="#+id/buttonRecord"
android:layout_alignEnd="#+id/buttonRecord"
android:layout_alignLeft="#+id/buttonRecord"
android:layout_alignStart="#+id/buttonRecord" />
</RelativeLayout>

If you want the content to scroll, perhaps try giving it a fixed height? Right now the height is set to wrap_content due to layout_height. I don't think you should be using android:height at all

If you want a fixed height TextView to scroll vertically with scrollbar,
define your XML layout file:
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:text="#string/text_string" />
define your Java class file:
TextView tv = (TextView) findViewById(R.id.textView);
tv.setMovementMethod(new ScrollingMovementMethod());

Related

Underline within a Textview in android studio XML

I want to put a horizontal line within a textview in android studio. I want to create a textview layout like this.
You can use this code to get TextView with a line .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Device"
android:layout_centerVertical="true"
android:layout_margin="3dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/tv_textview"
android:layout_margin="3dp"
/>
</RelativeLayout>
create linear layout with match_parent width
set orientation vertical
put text view child with wrap_content width
put view with 0dp width and weight = 1
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#000"
android:gravity="bottom" />
Draw custom drawable and set to drawableEnd to textview
Drawable can something like this..
and do not forgot to set textview width match parent
Do it Programitically Like..
(Use _ for Making a Line)
yourTextView.setText("Device_________________________");
yourTextView.setTextColor("Your Color Here");
and In XML file Set
Android:width = "MatchParent".
for your Text View.
Do this only if you are creating static layout.

Allign text inside TextView to it's border completely

Even when gravity is set to top the text has some padding between it and view's border. I need to text to completely touch the border.
Bellow you can see the gap I'm trying to get rid of.
And here is the layout used:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/someView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Here is some text"
android:textSize="30dp"
android:gravity="top" />
</LinearLayout>
Try to create 9.patch line and set it to your TextView: android:drawableTop="#drawable/your_line".
Then set android:drawablePadding="-10dp"
This trick must work perfectly.
Try this on TextView in your xml file :
android:includeFontPadding="false"
--
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/someView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Here is some text"
android:textSize="30dp"
android:includeFontPadding="false"
android:gravity="top" />
</LinearLayout>
In xml try,
android:paddingTop="-5dp"
Negative paddings always seem to work for me.
Set the height manually instead of wrapping the content.
The linear layout is the item with the padding. You need to modify that element as well to remove the space.

Android: Align one element below and in the middle of another

I have an ImageView and TextView. I want to place the TextView below the image view but with the middle of the TextView aligned with the middle of the ImageView (along the horizontal axis). If the text in the TextView changes to something much larger or smaller, the middle of the text always needs to remain aligned with the middle of the ImageView. Is this possible in xml?
Yes, you are simply looking to contain both elements in a vertical LinearLayout which has android:gravity set to center_horizontal.
Something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
... />
</LinearLayout>
Because the TextView's width is wrap_content, setting its gravity shouldn't be necessary. I would do it just for safety (and additionally, I may set the width to match_parent as well).
You can make use of RealtiveLayout as follows..
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
... >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<TextView
android:layout_below="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
If you want your textview to be of single line only then add following properties to TextView
android:ellipsezed="end"
android:singleLine="true"
Use a given layout and add it to any of your existing layout you get result what your looking for ..
Hope this explanation works for you..
set TextView android:layout_width="fill_parent" and set android:gravity="center" in TextView.
I think it help you.
Thanks

ExpandableListView problems

I'm trying to create an expandable list where I can make the height of the group_row smaller, to use less screen space. When I change the layout_height of the LinearLayout, it changes the height to what I want it, but all of the labels of each TextView aren't displayed; they disappear. However, when it is wrap_content, the text appears. Any ideas how to fix?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dp">
<TextView android:id="#+id/childname
android:paddingLeft="0dp"
android:textSize="16dp"
android:textStyle="italic"
android:layout_width="150dp"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Textview id should be android:id="#+id/childname"

How do I set the position of an image view in a relative layout in Android?

I'm trying to position an image below a TextView in a RelativeLayout but it doesn't work. when i set its position using android:layout_below. This is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#ccc"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/app_details_1"
android:text="#string/app_details_1"
android:textColor="#347"
android:gravity="center"
android:textSize="9pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/logo"
android:src="#drawable/secs"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/appdetails_1" <!-- I'm setting it here -->
/>
</RelativeLayout>
Instead it just places the image at the top left of the screen. How do I position it? Is layout_below a wrong positioning code?
There's a mistake in your xml. Must be
android:layout_below="#id/app_details_1"
it should be ok, but first try to make sure the textView is positioned on top by using layout_alignParentTop="true" for the textView and see if it does the trick.

Categories

Resources