I have a problem where when I click on my keyboard, the contents of my screen doesn't get pushed up--rather the keyboard simply overlaps everything (namely covers my ListView) on my screen. This is the structure of my layout:
<ScrollView>
<RelativeLayout>
</RelativeLayout>
</ScrollView>
<ListView>
</ListView>
<LinearLayout>
<EditText></EditText>
</LinearLayout>
I nested my RelativeLayout in a ScrollView because I thought that would make my entire layout scrollable, which would "push up" all the layouts so that the user can view those parts while typing his or her response. I also have in my AndroidManifest.xml: android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden" Here is an image of what is happening:
And here is my code. Any help would be appreciated!
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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="match_parent" android:fitsSystemWindows="true"
xmlns:fresco="http://schemas.android.com/tools"
android:id="#+id/comments_coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/comments_coordinator_layout"
>
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/view_post"
android:layout_width="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:layout_height="175dp"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="15dp"
android:id="#+id/poster_picture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
fresco:placeholderImage="#mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
/>
<TextView
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:id="#+id/poster_name"/>
<TextView
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_name"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/post_date"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_below="#id/poster_name"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_status" />
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_marginTop="225dp"
android:id="#+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message">
</ListView>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:hint="Comment back!"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
EDIT: My attempt to add in a parent LinearLayout for ScrollView. Issue is now:
The vertically scrolling ScrollView should not contain another vertically scrolling widget when I hover over ListView
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
xmlns:fresco="http://schemas.android.com/tools"
android:id="#+id/comments_coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/comments_coordinator_layout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/view_post"
android:layout_width="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:layout_height="175dp"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="15dp"
android:id="#+id/poster_picture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
fresco:placeholderImage="#mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
/>
<TextView
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:id="#+id/poster_name"/>
<TextView
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_name"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/post_date"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_below="#id/poster_name"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_status" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_marginTop="225dp"
android:id="#+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message">
</ListView>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:hint="Comment back!"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
EDIT: I think the best solution may be to create a custom ListView... that contains the same layout that is in each ListView item. Any suggestions or ideas on how to implement this?
EDIT: Tried #VanillaBoy's answer. I know the image produced is because I have marginTop = 225 dp but even if I remove it, when I click on my EditText, it only shows my ListView and my RelativeLayout above is hidden
EDIT: As per #Fllo's answer, I am still able to reproduce the error I had in the beginning with this layout, and so here is what I have in my layout. Also if it helps my Android Manifest looks like this android:windowSoftInputMode="adjustResize|stateAlwaysHidden">.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
xmlns:fresco="http://schemas.android.com/tools"
android:id="#+id/comments_coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/comments_coordinator_layout"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/view_post"
android:layout_width="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:layout_height="175dp"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="15dp"
android:id="#+id/poster_picture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
fresco:placeholderImage="#mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
/>
<TextView
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:id="#+id/poster_name"/>
<TextView
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_name"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/post_date"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_below="#id/poster_name"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_status" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:id="#+id/container_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message">
</LinearLayout>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:hint="Comment back!"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
Using an inner ListView with ScrollView should be avoided in Android. Indeed, these layouts have their own scroll detections and gestures. The solutions are to prevent the scroll gesture on the list or to calculate the height and expand it by default. But this will make too much work and don't respect the Android pattern and guidelines.
Instead of replace ListView by LinearLayout and keep the parent's ScrollView, as my old answer pointed out, I found a possible workaround, which has these steps:
Create your own ListView
Override onSizeChanged() which redraws the ListView when keyboard is opening
Get the lastVisiblePosition and retrieve its height in the previous method
Finally, move the list to the previous lastVisiblePosition and calculate the offset
Beside, set a headerView for the header picture container
And you need to update the child item's height before the user opens the
keyboard, so you could update the value in onClickListener of the
EditText
And it needs this kind of layouts:
layout's activity:
<CoordinatorLayout>
<AppBarLayout>
...
</AppBarLayout>
<RelativeLayout>
<CustomListView />
<LinearLayout>
...
</LinearLayout>
</RelativeLayout>
</CoordinatorLayout>
header's layout (which will be above the list):
<RelativeLayout>
<SimpleDraweeView />
<TextView />
...
</RelativeLayout>
Hum, that's all... So, good to go:
Create a Listview:
public class CustomListView extends ListView {
// last height item variable (updated from Activity)
public int lastItemHeight = 0;
public CustomListView(Context context) {
super(context, null);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
Override onSizeChanged():
#Override
protected void onSizeChanged(int w, final int h, int oldw, int oldh) {
// save last position visible before resize
final int lastPosition = super.getLastVisiblePosition();
// call super SizeChanged method
super.onSizeChanged(w, h, oldw, oldh);
// after resizing, show the last visible item at the bottom of new listview's height, above the edit text
// see : http://developer.android.com/reference/android/widget/AbsListView.html#setSelectionFromTop(int, int)
super.setSelectionFromTop(lastPosition, (h - lastItemHeight));
}
That's all for the ListView.
The lastItemHeight variable will be updated when the user clicks on the input (below the list, thanks to setting your "header" picture container as a headerView in your Activity).
Now, let see the Activity:
Setup your custom ListView and your Adapter:
// get custom listview element
final CustomListView list = (CustomListView) findViewById(R.id.container_list);
// example items child
ArrayList<String> items = new ArrayList<>();
for (int n=0; n<25; ++n) items.add("Blablabla n."+n);
// example adapter
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.item_list_text_simple, android.R.id.text1, items);
Create the HeaderView and set the Adapter:
// prepare the header content with picture
View header = getLayoutInflater().inflate(R.layout.test_header_image, null);
// set datas to the header elements (example)
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/fresco-logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) header.findViewById(R.id.poster_picture);
draweeView.setImageURI(uri);
// add the header to listview
list.addHeaderView(header, null, false);
// set the adapter
list.setAdapter(adapter);
Handle the softkeyboard open with EditText.setOnClickListener:
// when the user clicks on EditText...
editMessage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// set a new Thread
list.post(new Runnable() {
#Override
public void run() {
// get last position of child
int lastPosition = list.getLastVisiblePosition() - 1;
// if the list can give the view's last child
if (list.getChildAt(lastPosition) != null) {
// update the height of the last child in custom listview
list.lastItemHeight = list.getChildAt(lastPosition).getHeight();
}
}
});
}
});
That's all for the code! And the last thing (Ow.. where is the end?), here's the layouts:
The main layout of Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/comments_coordinator_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.Toolbar ... />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<com.package.name.CustomListView
android:id="#+id/container_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/send_message"/>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText ... />
<Button ... />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
The head layout of ListView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="225dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView ... />
<TextView ... />
<TextView ... />
<TextView ... />
</RelativeLayout>
Aw! I've finally finished. I really hope you will be able to have the right behaviour. I tested it, and it seems to work good enough.
Here's another workaround with adjustPan, but you have to keep your list starting at the bottom. Whereas this solution keeps any child at the bottom of the list when it's resize.
Hope you'll enjoy it ;)
add this in your manifest under Activity
<activity .......
....................
android:windowSoftInputMode="adjustResize"/>
Related
I'm trying to create an android app with RelativeLayout inside a scroll view which has a TextView with scrollbar but every time I try to scroll the TextView, RelativeLayout gets scrolled.
I've also tried following solutions but nothing works:
https://www.viralandroid.com/2015/10/how-to-make-scrollable-textview-in-android.html
how to make a relative layout scrollable when it has many children views?
RelativeLayout Scrollable
*My layout looks almost similar to 3rd link but with more controls.
Following is the code for my layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<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"
tools:context=".MainActivity"
android:scrollbars = "vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="365dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:text="#string/text1" />
<EditText
android:id="#+id/editText1"
android:layout_width="365dp"
android:layout_height="40dp"
android:layout_below="#+id/textView1"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:inputType="text"
android:text=""/>
<!-- Other Controls, about 15 of them -->
<TextView
android:id="#+id/testLogs"
android:layout_width="360dp"
android:layout_height="150dp"
android:layout_below="#+id/something"
android:layout_alignParentStart="true"
android:layout_marginStart="14dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="14dp"
android:background="#drawable/edit_text_background"
android:textColor="#color/editTestBorderColor"
android:enabled="true"
android:gravity="bottom"
android:hint="Process logs"
android:scrollbars="vertical"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:textSize="10dp" />
<Button
android:id="#+id/btnExecuteTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextLogs"
android:layout_alignParentStart="true"
android:layout_marginStart="67dp"
android:layout_marginTop="10dp"
android:text="#string/btnExecute" />
</RelativeLayout>
</ScrollView>
Problem : Unable to scroll Textview (android:id="#+id/testLogs")
Somehow if I have less controls(as long as layout's scrollable is not activated) then TextView's scroll is working.
Following are the device specs. that I'm using for testing :
Name : Huawei P10 lite
OS : Android 8.0
I have no idea why TextView scroll si not working?
Help Please!
try this
in XML file
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
and in java
tv_desc.setMovementMethod(new ScrollingMovementMethod());
scrollview.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
tv_desc.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
tv_desc.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
tv_desc.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Please do not mind for coding structure... Thank you.
in your layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:text="Enter SSID" />
<EditText
android:id="#+id/editText1"
android:layout_width="365dp"
android:layout_height="40dp"
android:layout_below="#+id/textView1"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:inputType="text"
android:text="" />
<!-- Other Controls, about 15 of them -->
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/editText1"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/testLogs"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="#+id/editText1"
android:layout_alignParentStart="true"
android:background="#color/colorPrimary"
android:enabled="true"
android:focusable="true"
android:hint="Process logs"
android:longClickable="true"
android:scrollbars="vertical"
android:text="#string/sample_text"
android:textColor="#color/WindowBackground"
android:textIsSelectable="true"
android:textSize="14sp" />
</androidx.core.widget.NestedScrollView>
<Button
android:id="#+id/btnExecuteTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/scroll1"
android:layout_alignParentStart="true"
android:layout_marginStart="134dp"
android:layout_marginTop="10dp"
android:text="Execute Test" />
<!--This is Additional code bellow -->
<!-- if you want to view multiple TextView with scrollable -->
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/btnExecuteTest"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/textView99"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/btnExecuteTest"
android:text="#string/sample_text" />
</androidx.core.widget.NestedScrollView>
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll3"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/scroll2"
android:layout_marginTop="50dp"
android:fillViewport="false"
android:isScrollContainer="false">
<TextView
android:id="#+id/textView100"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/textView99"
android:text="#string/sample_text" />
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
</ScrollView>
in you activity:
OnCreate():
TextView textView = findViewById( R.id.testLogs );
TextView textView1 = findViewById( R.id.textView99 );
TextView textView2 = findViewById( R.id.textView100 );
textView.setMovementMethod( new ScrollingMovementMethod( ) );
textView1.setMovementMethod( new ScrollingMovementMethod( ) );
textView2.setMovementMethod( new ScrollingMovementMethod( ) );
Preview:
Picture 1:
Picture 2:
I have to make (sort of) footer for empty screen. My parent layout is RelativeLayout1. Inside this layout I have ToolBar and below that is another RelativeLayout2.
Inside this RelativeLayout2 is Button and another RelativeLayout3. I made it that way, because I want to center RelativeLayout3 content in RelativeLayout2 and Button should always align bottom of the parent layout(RelativeLayout2)
I got answer for similar question before, but it doesnt always work. My problem now is that RelativeLayout3 is off-centered vertically(it's closer to the bottom).
How it should looks like
How it actually looks like
How to fix this?
Full Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/toolbar_round"
android:orientation="horizontal">
<include
android:id="#+id/toolBarContent"
layout="#layout/order_toolbar_layout" />
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/order_complete_footer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolBar"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/order_complete_image_text_layout"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/order_complete_image"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="#drawable/footer_image" />
<TextView
android:id="#+id/order_complete_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_image"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="-12dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text1"
android:textColor="#color/colorItemMinor"
android:textStyle="bold"
android:textSize="12sp" />
<TextView
android:id="#+id/order_complete_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_text1"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text2"
android:textColor="#color/colorItemMinor"
android:textSize="12sp" />
</RelativeLayout>
<Button
android:id="#+id/order_complete_continue_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:layout_marginEnd="#dimen/address_creation_button_padding_START_END"
android:layout_marginStart="#dimen/address_creation_button_padding_START_END"
android:layout_marginTop="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:background="#drawable/login_button_background_void"
android:text="#string/order_complete_screen_button_label"
android:textAppearance="#style/VoidLoginButtonTextAppearance" />
</RelativeLayout>
</RelativeLayout>
If I understood correctly, you should add the following to your order_complete_image_text_layout.
android:layout_above="#id/order_complete_continue_button"
#JanStoltman
Sounds like a question that was answered before but from my research I couldn't find a solution. My layout is roughly the following:
The main area is a container where I'll add/replace Fragments, and the bottom is where I place a bottom navigation menu. The pink View is a button that I need to place on top of my menu (and that's not working).
Every time I add a Fragment to the main view, my "Menu" text disappears, even though the TextView is added after the container View. Same with the pink Button, which is added after the bottom menu container (see my xml below).
How can I keep both "Menu" TextView and the pink Button always on top of my Fragments?
This is my xml:
<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:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_marginBottom="0dp"
>
</FrameLayout>
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
Try This`
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_height="70dp"
tools:targetApi="lollipop"
android:layout_marginLeft="71dp"
android:layout_marginStart="71dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/main_center_tv"
android:textSize="24sp"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_alignBaseline="#+id/menu_plus_img"
android:layout_alignBottom="#+id/menu_plus_img"
android:layout_toRightOf="#+id/menu_plus_img"
android:layout_toEndOf="#+id/menu_plus_img" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/menu_plus_img">
</FrameLayout>
`
You just have to change the order of the views in the layout while using a Framelayout
The complexity of your layout does not require a RelativeLayout so you just have to switch.
I don't really know why methods like bringToFront, bringChildToFront, or adding and removing View's children to change their indices didn't work. So I actually had to create a new layout structure.
Instead of:
RelativeLayout
...FrameLayout
...TextView
...FrameLayout
...Button
I did:
FrameLayout
...RelativeLayout
......FrameLayout
......FrameLayout
......TextView
...RelativeLayout
......Button
Whereas the second RelativeLayout has only a button and a transparent background. My full xml code is below as a reference.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_root_view"
android:layout_height="match_parent">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp" />
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:onClick="menuPlusBt"
android:elevation="5dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#drawable/green_circle"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
</FrameLayout>
I have the next layout
And when keyboard comes up, i wan't that green marked part of layout stays always visible. Another words i need to see both EditText and Button.
Here is my code sketch:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="16dp"
tools:context="com.mynfo.concept.auth.AuthActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/titleImageView"
android:layout_gravity="center"
android:src="#drawable/title_auth"
android:layout_weight="0"
android:layout_marginTop="48dp"
android:layout_marginBottom="48dp"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:id="#+id/barcode_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:inputType="number"
android:textColorHint="#color/darker_grey"
android:hint="edittext"
android:maxLength="15"
android:ellipsize="end"
android:ems="10"
android:background="#0000"
android:layout_gravity="left|center_vertical"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_menu_camera"
android:layout_gravity="right|center_vertical"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/grey"
android:layout_gravity="bottom"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.melnykov.fab.FloatingActionButton
android:id="#+id/button_scan"
android:layout_width="64dp"
android:layout_height="64dp"
fab:fab_colorNormal= "#color/turquoise"
fab:fab_colorPressed= "#color/turquoise_black"
fab:fab_colorRipple= "#color/turquoise_light"
android:src="#android:drawable/ic_menu_camera"
android:layout_gravity="center"/>
</FrameLayout>
<Button
android:id="#+id/button_link_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Authorize"
android:background="#drawable/button_authorize_selector"
android:enabled="false"
android:layout_weight="0"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
<TextView
style="#style/TextViewPrimary"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:textSize="16sp"
android:text="Enter your name"
android:gravity="center" />
<com.mynfo.concept.views.FontFitTextView
style="#style/TextViewSecondary"
android:text="And then you will got the access"
android:gravity="center" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/authenticatingView"
android:background="#fff">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:indeterminateOnly="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/authenticatingProgressBar"
android:layout_gravity="center"/>
</FrameLayout>
</FrameLayout>
</LinearLayout>
What haven't worked: adjustPan, adjustSize with or without layout weights.
Maybe I'm doing something wrong?
Thanks for the further help.
P.S. I know that this code feels redundant, but there were some purposes like screen adapting.
In your AndroidMenifest.xml file inside your tag use
windowsSoftInputMode = "adjustResize"
Or take whole layout inside ScrollView
windowsSoftInputMode = "adjustPan"
Example code snippet:
<activity
android:name=".activityname"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
Use
android:fillViewport="true" tag in ScrollView. And to avoid layout size bugs, use margin in Top ScrollView and don't use it in ScrollView child.
And add this in OnCreate
scrollView = (ScrollView) this.findViewById(R.id.scrollView);
scrollView.setVerticalScrollBarEnabled(false);
imageView = (ImageView) findViewById(R.id.imageView);
this.findViewById(android.R.id.content).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
scrollView.scrollTo(0, imageView.getHeight() + ((ViewGroup.MarginLayoutParams) imageView.getLayoutParams()).topMargin);
}
});
See the comments..
I'm trying to get an ImageView to overlap it's parent and create a speech balloon like, compound view. E.g:
I am not able to have the triangle at the bottom be part of the blue block and overlap any other views/controls that are placed below it.
Does anyone have a way of doing this?
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:id="#+id/appointment_ticket_signed_in_content_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/background_green" >
<ImageView
android:id="#+id/appointment_ticket_signed_in_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_action_accept"
android:contentDescription="#string/hello_world"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin" />
<TextView
android:id="#+id/appointment_ticket_signed_in_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/padding_large"
android:layout_marginRight="#dimen/padding_large"
android:layout_marginBottom="#dimen/padding_large"
android:textColor="#android:color/white"
android:textSize="18sp" />
</LinearLayout>
<ImageView
android:id="#+id/appointment_ticket_signed_in_down_arrow"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="centerInside"
android:src="#drawable/triangle"
android:contentDescription="#string/hello_world"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:paddingBottom="-25dp"
android:background="#color/important_text_orange" />
</merge>
I thought the above XML was the way to go but it seems a negative margin or padding bottom is unable to push the view outside its parent.
This XML is placed inside a relativelayout.
Does anyone know the answer to this?
EDIT
My situation:
Is there any way to overlap the next elements padding without having
direct access to it?
here is an xml file that creates something that could work. Try it out and let me know:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10sp" >
<ImageView
android:layout_width="match_parent"
android:layout_height="200sp"
android:layout_below="#+id/complete_bubble"
android:background="#123456" />
<RelativeLayout
android:id="#+id/complete_bubble"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-15sp" >
<RelativeLayout
android:id="#+id/main_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:padding="10sp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"
android:textColor="#FFFFFF" />
</RelativeLayout>
<ImageView
android:layout_width="20sp"
android:layout_height="20sp"
android:layout_below="#+id/main_block"
android:layout_marginLeft="20sp"
android:background="#000000" />
</RelativeLayout>
</RelativeLayout>
This negative margin works.
Method 1: Using the image of the balloon as the background image of a RelativeLayout and then add a TextView to that layout.
Method 2 (Also the more awesome method): Creating a custom view that will not only draw the speech balloon but also have a setText(String) method that will adjust the text that is drawn in the bubble and resize it to fit the text always. Then you open source that and share with the world.
If you want to create a custom view...
public class AwesomeTextBalloon extends View {
// constructors here
#Override
protected void onDraw(Canvas canvas) {
// first draw the balloon
// then draw the text
}
public void setText(String newText) {
// set text variable here
}
}
Then add the View programmatically or in the xml and call setText() to change the value of the balloon text.
Try Using this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#+id/header2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#android:color/transparent" />
<ImageView
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/pop_up" />
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="320dip"
android:layout_height="80dip"
android:layout_below="#id/header2"
android:background="#android:color/darker_gray"
android:fadingEdgeLength="0dip"
android:paddingLeft="1dip"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/appointment_ticket_signed_in_content_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background_green"
android:orientation="horizontal" >
<ImageView
android:id="#+id/appointment_ticket_signed_in_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:contentDescription="#string/hello_world"
android:src="#drawable/ic_action_accept" />
<TextView
android:id="#+id/appointment_ticket_signed_in_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_large"
android:layout_marginRight="#dimen/padding_large"
android:layout_marginTop="#dimen/padding_large"
android:textColor="#android:color/white"
android:textSize="18sp" />
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scroll"
android:background="#android:color/transparent" />
<ImageView
android:id="#+id/arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer"
android:layout_marginTop="-1dip"
android:src="#drawable/pop_dwn" />
</RelativeLayout>