How would I make an multi-line EditText with a vertical scroll bar go down to a certain spot? I want to do this inside of the Java code, and I'd prefer to do it with an EditText, but I'd be willing to use a ScrollView if I need to.
The EditText XML:
<EditText
android:id="#+id/theTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textAutoCorrect|textMultiLine"
android:scrollbars="vertical"
android:width="0dp" >
You can try using scrollTo api from the view.
Related
I want to make a android activity screen where a layout is sticked to bottom until scrollview get scroll to a certain position. like in this video samples links:
https://drive.google.com/open?id=0B14wNBitoI33LWtUNThqcXRIUWc
https://drive.google.com/open?id=0B14wNBitoI33QW1BOGR1di1TcGc
amarjain07's StickyScrollView maybe a solution you would want to look into. His methodology of assigning the "sticky" views as identified attributes in the layout xml is quite a nifty feature IMHO.
Use a RelativeLayout and put the Button-Container inside it.
Pass the container in your_scrollview_activity.xml the following attribute
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1 (reft)" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2 (right)"/>
</LinearLayout>
</RelativeLayout>
NOTE: You need to set a listener in your activity to get the ScrollViews current position / current height. With this current height you can calculate the "left space" to the bottom / end of the ScrollView. If your RelativeLayout reaches the bottom or if it's close to the bottom AND within the visible area, then call your animation.
I have multiline EditText in ScrollView. I need to make the whole EditText visible when keyboard is shown. Now it overlaps the bottom part of EditText showing only first line.
I have already read a lot of questions here, tried adjustPan/adjustResize combinations etc but nothing really helps.
<EditText
android:id="#+id/et_feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:lines="8"
android:maxLines="10"
android:minLines="6"
android:padding="10dp"
android:gravity="top|left"
android:inputType="textMultiLine"
android:background="#drawable/et_bg"
android:scrollbars="vertical" />
In AndroidManifest.xml:
<activity
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize"
...
windowSoftInputMode is the key but personally I found the configChanges help too.
And some more info on Handling Input Method Visibility
use the following xml code for your edittext:
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"/>
Place all your views in a top level ScrollView so that the content can be scrolled when the screen is not as tall as you exepct. It's not a good idea to assume the height of the screen for general layout purposes. Always use a ScrollView if you want your content to be scrollable on all screen sizes and orientations and keyboard states.
i'm actually really new at coding in java and on AndroidStudio and i'm trying to update an application that already exist.
I have 3 LinearLayout that look like 3 square inside each other and inside the last one, i have a TewtView.
the first one is the main one and is always visible.
When i put my two last LinearLayout in visibility="GONE" my LinearLayout disapear, and i want that my textView will be always visible, even if the LinearLayout that contains it are invisible.
It is possible?
<LinearLayout
style="#style/ColPlayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
style="#style/SquareBogey"
android:visibility="gone"
android:layout_width="70dp"
android:layout_height="50dp"
android:orientation="horizontal"
android:id="#+id/outersquare">
<LinearLayout
style="#style/SquareBogey"
android:visibility="gone"
android:layout_width="60dp"
android:layout_height="40dp"
android:orientation="horizontal"
android:id="#+id/innersquare">
<TextView
android:id="#+id/PlayerCJ01"
style="#style/ColCJPlayer"
android:layout_height="wrap_content"
android:ems="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Just ask me if you need more informations.
Thanks
When setting the visibility of a parent layout to GONE or INVISIBLE, all its children will also become GONE or INVISIBLE.
If you want to show the TextView but not its parent LinearLayout, than you could either move the TextView out of the LinearLayout, or you could remove the styling of the LinearLayout so it will look like its gone, but obviously it's still there.
Setting the visibility of the LinearLayout to GONE and its child TextView's visibility to VISIBLE won't work and therefore is not an option.
Instead of setting the visibility as GONE for the LinearLayouts, maybe you can set their background/border as transparent by changing their style.
It depends on your use case, if it suits your need.
I have an edittext enclosed within a textinputlayout from the support library and I'm finding it impossible to make the hint appear in the center of the field. I've tried all the usual tricks to be found in other stackoverflow discussions, as you can see from the code sample, but the hint still stubbornly appears on the left of the edittext. How can I solve this?
Please don't suggest using paddingLeft or paddingStart to do this - I want something that's going to work cleanly across different devices so it has to be a straight solution rather than a workaround.
Just to be clear: If I remove the textinputlayout then the hint is properly centered. It's the textinputlayout that's causing the problem here.
<android.support.design.widget.TextInputLayout
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_marginRight="30dp"
android:layout_marginEnd="30dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:ellipsize="start"
android:maxLines="1"
android:inputType="textPersonName"
>
<EditText
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="#string/somehint"
android:textColorHint="#color/somecolor"
android:textSize="20sp"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:cursorVisible="true"
android:textCursorDrawable="#null"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:inputType="textPersonName"
android:maxLines="1"
android:ellipsize="start"
/>
</android.support.design.widget.TextInputLayout>
Using the latest version of the support library:
compile 'com.android.support:design:22.2.1'
Edit - things I've tried to resolve this:
1) replacing Edittext with android.support.v7.widget.AppCompatEditText - doesn't work
2) using app:hintTextAppearance="#style/TextAppearance.AppCompat" inside the textinputlayout - doesn't work
3) Instead of defining the hint in the edittext, setting the hint programmatically using textinputlayout.sethint inside the activity - doesn't work: the hint appears on the left.
4) Setting the hint on the edittext in onActivityCreated. This appeared to work initially, but I discovered that although the hint appears centered the functionality of inputtextlayout becomes broken and clicking on the edittext no longer performs the hint animation.
To center the hint text in your EditText just add the following two attributes in your EditText. This will do the trick.
android:ellipsize="start"
android:gravity="center_horizontal"
There doesn't seem to be a way to do this (at least not that I can find). As a workaround I tried using the MaterialEdittext 3rd party library - also not ideal since although the small animated hint is centered, it appears inside the text box instead of outside it:
https://github.com/rengwuxian/MaterialEditText
Im searching a way how to fix a TextView on a ,for example, transparent square like in the Picture I did in Paint.net .So the TextView should in front of the transparent square (ImageView).Also it should stretch when the screen is bigger.
http://www7.pic-upload.de/22.02.14/24vtze5ulxc2.png
How can I solve the problem ?
Thanks !
Use a FrameLayout
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/semi_transparent_background"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is my text."/>
</FrameLayout>
Alternatively, you could do something similar with a relative layout.
You can use RelativeLayout or FrameLayout for that.
<FrameLayout>
<ImageView>
<TextView>
</FrameLayout>
Your textview will appear on ImageView.
Although note that, RelativeLayout has double taxation tradeoff. Each measure and layout happens twice.
Simply ordering the items in RelativeLayout from top to bottom in the XML will make each in turn move to the front compared to the others above it.