Adjust listview along with expandable edittext in chat app - android

In my chat application I have a layout with a listview (a chat between two users) and an edittext input for writing a new message for the same conversation.
The first problem happens when a user clicks on input - a soft keyboard pops up but the listview remains at the same position as before, instead of jumping up along with an edittext input and keeping the same interval between.
The second problem is when I dismiss keyboard and return to the default state with a large number of lines, the listview again remains at the same position and the edittext overlaps it.
My layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/main_bg"
android:gravity="right"
android:orientation="vertical" >
<include
android:layout_alignParentTop="true"
layout="#layout/actionbar_layout" />
<ListView
android:id="#+id/lsvMessage"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="0dp"
android:layout_marginTop="50dp"
android:background="#color/_transperant"
android:divider="#null"
android:dividerHeight="0dp">
</ListView>
<LinearLayout
android:id="#+id/txtMsgLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:background="#color/_transperant">
<EditText
android:id="#+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:hint="#string/btn_ask_hint"
android:background="#drawable/edit_text_style"
android:textColor="#color/_white"
android:singleLine="true"
android:textAlignment="viewStart"
android:inputType="textMultiLine|textCapSentences|textNoSuggestions"
android:layout_weight="1">
</EditText>
<RelativeLayout
android:id="#+id/message_spinner_layout"
style="#style/layout_fill_width"
android:gravity="right"
android:layout_weight="0">
<Spinner
android:id="#+id/message_lng_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:gravity="right"
android:paddingLeft="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:background="#drawable/spinner_setting"
android:layout_alignBottom="#id/message_lng_spinner"
android:layout_marginBottom="12dp"
android:layout_marginRight="20dp" />
</RelativeLayout>
<Button
android:id="#+id/btnSend"
style="#style/submit_button_style"
android:text="#string/btnSend"
android:background="#drawable/submit_button"
android:layout_weight="0"/>
</LinearLayout>
</RelativeLayout>
I tried to fix it programmatically and count the high of edittext layout to move listview accordingly but it didn't work.
final View activityRootView =
((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
final View msgLayout = (ViewGroup)findViewById(R.id.txtMsgLayout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener
(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) {
scrollMyListViewToBottom();
} else {
int heighListview = msgLayout.getHeight();
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)
lsvMessage.getLayoutParams();
params.setMargins(0,50,0,heighListview);
lsvMessage.setLayoutParams(params);
}
}
});
Can I fix it with a properly marked up layout or code behind?

I had same problem. I have tried all answers in the stackoverflow, but not have any final solution.
I found solution from google native message app:
ComposeMessageActivity layout
ComposeMessageActivity here have a method: "smoothScrollToEnd"
and there are have a MessageListView.java class for detect onSizeChanged.

Related

Listview in dialog with header and footer

I have a listview in my dialog and then I have to use the header layout and footer layout. the way I am doing it , aligning my header layout to top and the footer layout to bottom . but it has a problem. take a look at below picture ..
But by doing that the dialog gets Longer in size which is not expected
I am traped in this situation. Well If i align my footer with the listview end then the footer gets out of the screen. which is also not expected.
What I want :
I want that My listview should be visible in the center of dialog with the header layout align top and the footer layout align to the bootm of the dialog botttom border and it should not take the full length of the screen.
Isnt there a way to align the footer to the bottom of the dialog and dialog it self maintain its height (Note: I do not want to give the dialog hard coded height as I want the dialog to be look same on all devices. )
Please help I am stuck in the situation. If we look at the google dialog whcih comes while installing the app, it has short dialog with the listview in center of it and buttons are aligning to bottom of the dialog. How they are doing it?
Here's the dynamic solution for your problem..
Sample dialog xml file name activity_list_test.xml..
<?xml version="1.0" encoding="utf-8"?><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:background="#color/page_bg"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Header Button" />
<ListView
android:id="#+id/lvCommon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Button" /></LinearLayout>`
Here's the calling from a fragment/activity where you want..
private void showAlert() {
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
View view = LayoutInflater.from(getActivity()).inflate(R.layout.activity_list_test, null);
dialog.setView(view);
dialog.setTitle(null);
dialog.setMessage(null);
ArrayList<String> mList = new ArrayList<>();
for (int i = 0; i < 15; i++) {
mList.add("ABC");
}
ListView lvCommon = (ListView) view.findViewById(R.id.lvCommon);
int deviceHeight = getScreenSize(getActivity()).y;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, deviceHeight / 3,1f);
lvCommon.setLayoutParams(layoutParams);
lvCommon.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, mList));
dialog.setCancelable(false);
dialog.show();
}
There device height will be auto measure and according to it the dialog size will be "deviceheight/3"..so it will be maintain in all devices..
Now you need the method getScreenSize..So here's it is::
public static Point getScreenSize(Activity act) {
int screenWidth = 0;
int screenHeight = 0;
final DisplayMetrics metrics = new DisplayMetrics();
act.getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;
return new Point(screenWidth, screenHeight);
}
You can set layout to your Dialog like below way
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/header_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Header Text"
android:gravity="center|top"/>
<ListView android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="center_vertical/>
<TextView android:id="#+id/footer_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Footer Text"
android:gravity="center|bottom"/>
</LinearLayout>
It will set Header View to Top,ListView to Center and Footer View to Bottom
You can try this one,.. create one xml and copy paste this code and set your dialog xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
android:gravity="center"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/table_rl"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="vertical">
<TextView
android:id="#+id/your_items_tv"
android:textColor="#color/text_black"
customFontPath="lato_black.ttf"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="20dp"
android:text="HEADING"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_below="#+id/your_items_tv"
android:paddingBottom="5dp"
android:layout_marginTop="10dp"
android:paddingTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textColor="#color/text_black"
customFontPath="lato_bold.ttf"
android:layout_gravity="center"
android:gravity="left"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TOP BAR"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/table_rl"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00ff">
<TextView
android:padding="5dp"
android:textSize="18dp"
android:textColor="#color/text_black"
customFontPath="lato_bold.ttf"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Bottom Bar "/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Button's text gets wrong alignment after a setText() call on a TextView

In my case I have an activity with a TableLayout which contains a few views such as a Button with id 'Number1' and a TextView with id 'password'.
When I hit the button, its event handler gets called and one of the things it does is set the password TextView text. After this, the button's text becomes misaligned - instead of the original center alignment, the text inside the button becomes aligned at the bottom.
I am using Android Studio 1.1 Beta 4 and the project has compileSdkVersion set to 21, minSdkVersion set to 19 and targetSdkVersion set to 21.
Below I have provided snippets of the relevant code.
Event handler snippet ...
public void buttonNumberClick(View view) {
TextView passwordText = (TextView) findViewById(R.id.password);
Button sourceButton = (Button)view;
String sourceText = sourceButton.getText().toString();
String text = passwordText.getText().toString();
if (text.length() < 4) {
int number = Integer.parseInt(sourceText);
String newText = text + Integer.toString(number);
// After this below line, the button text of the clicked button (Number1) becomes bottom aligned.
passwordText.setText(newText);
}
}
Layout snippet ...
<TableLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<TableRow
android:minHeight="130dp"
android:layout_height="0dp"
android:layout_weight="0.5">
<LinearLayout
android:layout_weight="0.5"
android:layout_row="0"
android:layout_column="1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:orientation="vertical">
<TextView
android:layout_gravity="center_horizontal"
android:id="#+id/enterPinTextView"
android:textSize="25sp"
android:text="Enter PIN"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="center_horizontal"
android:id="#+id/password"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/progressRing"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:progressDrawable="#drawable/circular_progress_bar" />
<TextView
android:text="5.0"
android:id="#+id/progressRingText"
android:textSize="20sp"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</TableRow>
<TableRow
android:gravity="bottom|center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_weight="0.25"
android:layout_height="0dp"
android:layout_width="wrap_content">
<Button
android:id="#+id/buttonTest"
android:text="Test"
android:minHeight="50dp"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:onClick="buttonTestClick" />
<Button
android:id="#+id/Number1"
android:text="1"
android:minHeight="50dp"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
android:onClick="buttonNumberClick" />
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
After looking at the few similar occurrences on Stack Overflow like this, I tried a few different things including programmatically setting the text of the Button and also setting its gravity and padding again. None of this worked.
I arrived at this solution by trial and error - Hide and then show the button before and after the offending call to setText. Also, note that you have to set visibility to GONE rather than INVISIBLE. This is possibly forcing the layout engine to create the button again, with the correct alignment.
New event handler shown below.
public void buttonNumberClick(View view) {
TextView passwordText = (TextView) findViewById(R.id.password);
Button sourceButton = (Button)view;
String sourceText = sourceButton.getText().toString();
String text = passwordText.getText().toString();
if (text.length() < 4) {
int number = Integer.parseInt(sourceText);
String newText = text + Integer.toString(number);
// Fix the issue of the button text being mis-aligned after the below call to setText.
sourceButton.setVisibility(View.GONE);
passwordText.setText(newText);
// Fix the issue of the button text being mis-aligned after the above call to setText.
sourceButton.setVisibility(View.VISIBLE);
}
}

How should inflating go right way?

I need to have like several listviews on a scrollview which Android doesn't allow me to do so I decided to make it manually to simply inflate some listrows on a vertical LinearLayout, but everything goes not the right way
private void fillData(final ViewGroup parent, final ArrayList<Person> array ){
for (int i=0;i<array.size();i++){
final View view = lf.inflate(R.layout.personal_listrow, parent,true);
parent.setBackgroundColor(getActivity().getResources().getColor(R.color.background_light_darker));
view.setBackgroundColor(getActivity().getResources().getColor(R.color.background_night_lighter));
TextView tvName=(TextView) view.findViewById(R.id.tvName);
TextView tvStatus=(TextView) view.findViewById(R.id.tvStatus);
TextView tvGender=(TextView) view.findViewById(R.id.tvGender);
//fill textviews with info, set the onClickListeners and so on
}
So what I get - the view.setBackgroundColor paints parent as well .
parent is a vertical LinearLayout, view is horizontal LinearLayout - it's strange that I don't paint inflated element only so please explain me why
The next thing - after I add something to array - 1st element changes and all the rest is with unchanged text. However, I walked through the code with debugger - it passes every element and sets text.
The clicklisteners works on the 1st element only..
Would you plz explain
here's vertical , parent layout - nothing special:
<LinearLayout
android:id="#+id/rodll"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
the inflateable listrow is nothing special also :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvStatus"
android:layout_width="0dp"
android:layout_weight=".3"
android:maxLines="1"
android:layout_height="wrap_content"
android:text="tvSt" />
<TextView
android:id="#+id/tvName"
android:layout_weight="1"
android:layout_width="0dp"
android:maxLines="1"
android:layout_height="wrap_content"
android:text="tvName" />
<TextView
android:id="#+id/tvGender"
android:layout_weight=".1"
android:layout_width="0dp"
android:maxLines="1"
android:layout_height="wrap_content"
android:text="tvGender" />
<com.andexert.library.RippleView
android:id="#+id/removeRipple"
xmlns:ripple="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="30dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginRight="7.5dip"
android:padding="3dp"
ripple:rv_alpha="255"
ripple:rv_zoom="true"
ripple:rv_zoomScale="0.8"
ripple:rv_type="rectangle">
<ImageView
android:id="#+id/remove_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/remove" />
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:id="#+id/addRipple"
xmlns:ripple="http://schemas.android.com/apk/res-auto"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginRight="7.5dip"
android:padding="3dp"
ripple:rv_alpha="255"
ripple:rv_zoom="true"
ripple:rv_zoomScale="0.8"
ripple:rv_type="rectangle">
<ImageView
android:id="#+id/add_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/add" />
</com.andexert.library.RippleView>
</LinearLayout>
So. what's the problem and how to solve it?

Android - Custom Keyboard on manually inflated listview row not showing

Good day.
I have an android application. In my application, I have a custom listView with 5 columns that are textViews. The user can click the rows, once he does, the row layout will change, changing the last 2 textViews to EditTexts. I then register the new EditTexts onto my custom keyboard taken from this example - kindly note that I did a functional copy-paste of his example with regards to the custom keyboard class and how to make it work in the main layout. However, when I click the EditText in the row, my custom keyboard does not show up at all.
I have a global variable as such:
CustomKeyboard mCustomKeyboard;
And in my onCreate() method in the activity, I do:
mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.custom_keyboard);
This is my layout, I have the KeyboardView at the bottom of the Layout:
<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:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".SearchResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- A lot of views go here, enclosed in my linear layout -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Here is the code that changes the layout. What I do is that I take the row values from the old layout, get the new layout search_result_inflate, then set the texts of the new layout using the values I got. Kindly note the mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult); line after inflating the layout:
private void changeLayout(final View view){
//get views from old layout
TextView textViewQuantity = (TextView)view.findViewById(R.id.qtyInput);
TextView textViewDiscountReq = (TextView)view.findViewById(R.id.discInput);
TextView textViewName = (TextView)view.findViewById(R.id.dialogItemName);
TextView textViewPrice = (TextView)view.findViewById(R.id.price);
TextView textViewDiscount = (TextView)view.findViewById(R.id.discount);
//store values in strings
String itemName = textViewName.getText().toString();
String itemPrice = textViewPrice.getText().toString();
String itemDiscount = textViewDiscount.getText().toString();
String itemQty = textViewQuantity.getText().toString();
String itemDisc = textViewDiscountReq.getText().toString();
//set the view to gone
textViewQuantity.setVisibility(View.GONE);
textViewDiscountReq.setVisibility(View.GONE);
textViewName.setVisibility(View.GONE);
textViewPrice.setVisibility(View.GONE);
textViewDiscount.setVisibility(View.GONE);
//get the old layout
LinearLayout ll_inflate = (LinearLayout)view.findViewById(R.id.search_result_layout);
//get the inflate/new view
View child = getLayoutInflater().inflate(R.layout.search_result_inflate, null);
//get the views in the new view, populate them
TextView newName = (TextView)child.findViewById(R.id.dialogItemName);
newName.setText(itemName);
TextView newDiscount = (TextView)child.findViewById(R.id.discount);
newDiscount.setText(itemDiscount);
TextView newPrice = (TextView)child.findViewById(R.id.price);
newPrice.setText(itemPrice);
EditText qtyInput = (EditText)child.findViewById(R.id.qtyInputSearchResult);
qtyInput.setText(itemQty);
EditText discInput = (EditText)child.findViewById(R.id.discInputSearchResult);
discInput.setText(itemDisc);
//show new layout
ll_inflate.removeAllViews();
ll_inflate.removeAllViewsInLayout();
ll_inflate.addView(child);
mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult);
}
Here is my search_result_inflate.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.54"
android:gravity="center"
android:text="Item Name"
android:textSize="23sp" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:gravity="center"
android:text="Price"
android:textSize="23sp" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.10"
android:gravity="center"
android:text="Discount"
android:textSize="23sp" />
<EditText
android:id="#+id/qtyInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:background="#layout/edittext_selector"
android:gravity="center"
android:hint="qtyInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" >
</EditText>
<EditText
android:id="#+id/discInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.11"
android:background="#layout/edittext_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="discInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
As you can see, I have 2 editTexts and I registered qtyInputSearchResult to the custom keyboard class. However, the custom keyboard does not show up.
I also tried to use the custom keyboard class on an editText in another activity and it works just fine. Am I missing something here? I'm confused as to why the custom keyboard does not show up properly.
Any help is very much appreciated, thank you.
Got it, I placed the keyboard layout in the search_result_inflate.xml like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<!-- a lot of components here -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>

How to position layout off the screen

I need to reach the following result:
My RelativeLayout overlay initially should look like that . So only 20% of the layout should be seen.
when Button is pressed i apply Animation so that layout goes up and looks the following
Overlay layout is placed in the parent RelativeLayout and has number of ImageButtons in it.
<RelativeLayout
android:id="#+id/overlay"
android:layout_width="match_parent"
android:layout_below="#+id/actionbar"
android:layout_height="wrap_content"
android:background="#drawable/backgroundfeedme"
android:clickable="true"
>
-----number of img buttons here --
</RelativeLayout>
I was trying to set up its initial position as follows
rlOverlay = (RelativeLayout) v.findViewById(R.id.overlay);
ViewTreeObserver vto = rlOverlay.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
WindowManager wm = (WindowManager) MainActivity.appContext.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int height = display.getHeight(); // deprecated, my app is for API 2.1+
rlOverlay.layout(0, (int)(height*0.8), rlOverlay.getMeasuredWidth(), rlOverlay.getMeasuredHeight());
}
});
Unfortunately the code above doesnt affect position of the layout.
I also cant use marginTop, because it squeezes the layout.
So .. how to position my layout so that only 20% of it is visible initially?
Thanks.
i had same requirment. what i did is put two relative layout. in first layout took button and below it second layout with rest of my views and Visiblity = gone.
from code: when i click on Button i made seond layout visiblity = Visible and animate it.
here's code:
<RelativeLayout
android:id="#+id/llShopping"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bar_green" >
<Button
android:id="#+id/btnShoppingListAddItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bar_green"
android:gravity="center"
android:paddingLeft="5dp"
android:text="Add Item"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/relAddItemChild"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnShoppingListAddItem"
android:layout_marginBottom="10dp"
android:visibility="gone" >
<View
android:id="#+id/gl"
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:background="#android:color/white" />
<EditText
android:id="#+id/edtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gl"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:hint="Item Name..." />
<Button
android:id="#+id/btnSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edtItemName"
android:layout_centerHorizontal="true"
android:text="Please pick store" />
<Button
android:id="#+id/btnAddToList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btnSpinner"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:background="#drawable/btn_blue"
android:padding="5dp"
android:text="Add To List"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>

Categories

Resources