I have created this, with 1 webview and 1 textview (tried also edittext) and a scrollview, but in the preview it explains all lines, when i launch it explain only 1 line. i tried to rmeove scrollview, webview...nothing...how can i do? Thank you
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".ActivityMappa"
tools:showIn="#layout/activity_mappa"
>
<WebView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="50dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="20dp"
android:id="#+id/webview" />
<EditText
android:id="#+id/testo"
android:layout_width="match_parent"
android:layout_height="126dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/transparent"
android:clickable="false"
android:focusable="false"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:text="#string/testonavi_spawn"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
Preview on Android Studio
Preview on my Phone/Emulator
In strings.xml you must escape all ' of testonavi_spawnby \', for example: ...all\'Avamposto...
Take a look into the documentation for String resources.
Edittext height is given as 126dp. You'll not be able to see 30 lines in it. so make the layout_heigh of the edittext as "wrap_content". This will make the edittext dynamic. As the total content is in scrollview, you'll still be able to scroll and see the complete content
Did you try using
android:minLines=10
where 10 is the number of lines you want it to appear.
Since you have set the android:width="match_parent" maybe its going beyond the view change it to android:layout_width="wrap_parent".
Change the code to:
<TextView
android:id="#+id/testo"
android:layout_width="wrap_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:minLines="10"
android:text="#string/testonavi_spawn"
android:textSize="15sp" />
NOTE: Always use a TextView to display the text and EditText to edit any texts.
Related
Textview items are not visible. The Button below them is.
Tried changing the LinearLayout with RelativeLayout, changed the match_parent and content with 0dp. None of them worked. Only the button shows in the right spot as though the TextViews are there but invisible. These views are called in the onCreate() of the Activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".EnterData">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDateIn"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
tools:text="Date"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDescIn"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
tools:text="Description"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvAmountIn"
tools:text="California"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:textColor="#000"
android:textSize="17sp"/>
<Button
android:id="#+id/btnSendData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Send Data"/>
</LinearLayout>
You try to use android:text instead of tools:text. tools:textonly visible in the Android Studio.
Or you should use yourTextView.setText("yourText") if you are using tools:text.
Instead of using tool:text in xml use android:text="abc" in textView.
As tool:text is used for android studio layout preview . It does not show text when you run your application .
While android:text is used to set text to textview, button etc.
Yep, it was all working and just placing android:text showed it.
Thank you very much.
I have this xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/horizontalPadding"
android:paddingRight="#dimen/horizontalPadding"
android:paddingTop="#dimen/verticalPadding"
android:paddingBottom="#dimen/verticalPadding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:ems="10" />
</LinearLayout>
</LinearLayout>
When my app is running the keyboard is visible and clickable, but the value of editText doesn't change. how can i resolve it?
If someone is interesed, i resolved using the EditText.requestFocus()
Try to replace android:ems="10" with android:maxEms="10" or android:maxLength="10", I'm not sure, what you want to achieve with this parameter
Hope, this will solve you issue
android:ems="10" is all about width of the view, however you are overriding this setting by layout_width property setting to match_parent.
It looks like you would want two EditTexts to be stretch equally and fill that LinearLayout, so here you wouldn't need ems at all. You would need maxLength instead.
Also note that to stretch those EditTexts you should set their widths to 0dp and set their weight to 1 (or something else. They should be equal).
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:maxLength="10" />
</LinearLayout>
For me, the problem was, I didn't let my PopupWindow be focused. Then I found out that my PopupWindow focusable was by default set to false. So, I try to add 1 new parameter that explicitly tells the PopupWindow is focusable. You can see it in my screenshot below. Previously I didn't pass the false value, only the first three values.
Now, I can type anything in the EditText. This one took a whole day to be resolved. 🤣
I have a TextView inside a LinearLayout which displays only a part of its text without wrapping to a newline and cannot understand why. It doesn't even show the ellipsis somewhere.
The TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
i also tried layout_weight=0 along with layout_height=0 but still no luck. All the siblings inside the LinearLayout have layout_height=wrap_content set.
EDIT
Okay apparently it works when a fixed width is set, but neither with fill_parent nor with match_parent. Is this the expected behaviour?
Per Request the whole layout
Note that inside the FrameLayout is another invisible one, which is rather long
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="#style/ContentBody"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/progress"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_title"
style="#style/TxtTitle" />
<TextView
android:layout_width="410dp"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="410dp"
android:layout_height="wrap_content"
android:id="#+id/progress_bar_view"
android:progress="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_start"
android:id="#+id/progress_text_view"
style="#style/TxtSecondary" />
</LinearLayout>
</FrameLayout>
if you want to always show text in n lines, just add android:lines="n",
or if it's not work, try to use for your TextView ->
android:textAppearance="?android:attr/textAppearanceLarge"
hope that will help.
The code snippet is wrapping to multiline perfectly. There might be some problem with the IDE, which is not previewing properly. Test on a real device.
I have a following xml for my activity.
<LinearLayout 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"
tools:context=".Activity1" >
<RelativeLayout
android:id="#+id/titleStoryRelativeLayout"
android:layout_weight="#string/titleWeight"
android:layout_width="fill_parent"
android:layout_height="0dip">
<TextView
android:id="#+id/titleStory"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/contentTextViewLayout"
android:layout_weight="#string/contentTextViewWeight"
android:layout_width="fill_parent"
android:layout_height="0dip">
<TextView
android:id="#+id/textViewStory1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/footerStoryRelativeLayout"
android:layout_weight="#string/footerWeight"
android:layout_width="fill_parent"
android:layout_height="0dip>
<Button
android:id="#+id/buttonPrevious"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:onClick="loadPrevious"
android:text="#string/stringButtonPrevious"/>
<Button
android:id="#+id/buttonNext"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:onClick="loadNext"
android:text="#string/stringButtonNext"/>
Here I am loading my Textview (#+id/textViewStory1) dynamically from my code with some text. The problem is that during loading, few lines go beyond the screen. I am planning to enable scrolling so as user can scroll down to view those missing lines. But the scrolling should only be limited till the last line and not beyond. Any suggestion on how can I set that?
Set these settings for your textview:
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
You can then set it to be scrollable in java:
TextView.setMovementMethod(new ScrollingMovementMethod());
Try to use ScrollView (official documentation)
You can limit the Height of TextView to match the number of lines you want to see, after that put your TextView in a ScrollView
I had done a simple example to demonstrate this...
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="#+id/tv1"
/>
</ScrollView>
Observe how I fixed ScrollView's height and matched TextView's height to it.
I had answered this exact question before here , please check for existing answers on SO before asking them again.
Hello I am trying to get text to display like it does in terminal or cmd. And by that I mean a window of text that with each input makes a new line and then displays the bottom line of the TextView, and there would be a set amount of lines always on the screen.
It sounded easy to do, but now that I started I'm not sure how to do it.
I tried putting a TextView in a ScrollView like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:id="#+id/tv1"
android:layout_width="wrap_content"
android:minLines="11"
android:maxLines="11"
android:layout_height="wrap_content"/>
</ScrollView>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="buttonclick"
android:text="Button" />
</LinearLayout>
and then
sss=et1.getText().toString();
tv1.append("\n"+sss);
to add new lines
This all works but I really have no idea how to make the TextView go to the bottom, right now it just cuts off when I hit the max number of lines.
I definitely don't expect anyone to write my program for me. I am here to learn
Thanks for your time!
Call fullScroll(View.FOCUS_DOWN) on the ScrollView after appending the text.