ok so I have a custom dialog that it shows up as the left picture. And I want with a click of a button (black square) to take the full screen like the right screen but don't go behind the keyboard. How can I do this?
for now my dialog is like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/comments_relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<EditText
android:id="#+id/user_comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top"
android:textColor="#000000" />
<TextView
android:id="#+id/char_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="2048" />
<Button
android:id="#+id/fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#drawable/full_screen_button_selector"
android:minHeight="1dp"
android:minWidth="1dp" />
</RelativeLayout>
I tried this on onclick but it doesn't work
RelativeLayout r = (RelativeLayout) findViewById(R.id.comments_relative_layout);
FrameLayout.LayoutParams _rootLayoutParams = new
FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
r.setLayoutParams(_rootLayoutParams);
anyone has an idea how to do this?
Try this:
myDialog.show();
Window window = myDialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
Related
I have a view in which I'm creating a PopupWindow. In this PopupWindow, I have a text box (EditText). When clicking to edit the text, the keyboard opens and the whole view goes up, but the top of the view goes under the action bar view smoothly. So far so good.
I now have added an empty GridView without any further configuration to the PopupWindow, and now the same scenario happens but the whole top part of the view goes on top of the action bar view and not smooth (the popup becomes a mess, when keyboard disappears the popup location changes for couple of seconds and there are "leftovers" from the keyboard for a second). It also happens with ListView.
I want the top part of the view to go under the 'ActionBar` smoothly, as it should.
Any ideas?
UPDATE: By adding the GridView programatically I partially solved it on a couple of devices, but on some devices it's still happens.
Displaying the popupwindow:
pView=inflater.inflate(R.layout.activity_packbuild, (ViewGroup)mainActivity.findViewById(R.layout.activity_main));
pw = new PopupWindow(
pView,
ma.f.getView().getMeasuredWidth(),
ma.f.getView().getMeasuredHeight(),
true);
pw.showAtLocation(mainActivity.getWindow().getDecorView().findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
GOOD:
BAD:
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lID">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rID"
android:background="#drawable/back5">
<ImageView
android:layout_width="125px"
android:layout_height="200px"
android:id="#+id/mImageView"
android:background="#drawable/com_facebook_picker_default_separator_color"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_marginTop="300dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_below="#+id/mImageView"
android:layout_marginTop="22dp"
android:layout_toRightOf="#+id/lButton"
android:layout_toLeftOf="#+id/rButton" />
<ImageView
android:layout_width="125px"
android:layout_height="200px"
android:id="#+id/imageViewRR"
android:background="#drawable/com_facebook_picker_default_separator_color"
android:layout_alignTop="#+id/mImageView"
android:layout_toRightOf="#+id/mImageView"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="125px"
android:layout_height="200px"
android:id="#+id/imageViewLL"
android:background="#drawable/com_facebook_picker_default_separator_color"
android:layout_alignTop="#+id/mImageView"
android:layout_toLeftOf="#+id/mImageView"
android:layout_marginRight="20dp" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/lButton"
android:layout_below="#+id/editText"
android:layout_alignLeft="#+id/imageViewLL"
android:layout_alignStart="#+id/imageViewLL" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/rButton"
android:layout_alignTop="#+id/lButton"
android:layout_alignRight="#+id/imageViewRR"
android:layout_alignEnd="#+id/imageViewRR"
android:layout_marginTop="5dp" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/picButton"
android:layout_alignTop="#+id/galleryButton"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:background="#drawable/camera2" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/videoButton"
android:background="#drawable/video"
android:layout_alignTop="#+id/galleryButton"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="125px"
android:layout_height="200px"
android:id="#+id/imageViewR"
android:background="#drawable/com_facebook_picker_default_separator_color"
android:layout_above="#+id/editText"
android:layout_alignRight="#+id/sendButon"
android:layout_alignEnd="#+id/sendButon" />
<ImageView
android:layout_width="125px"
android:layout_height="200px"
android:id="#+id/imageViewL"
android:background="#drawable/com_facebook_picker_default_separator_color"
android:layout_alignTop="#+id/mImageView"
android:layout_alignLeft="#+id/editText" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/galleryButton"
android:background="#drawable/gallery"
android:layout_alignTop="#+id/rButton"
android:layout_alignRight="#+id/imageViewR" />
<ImageButton
android:layout_width="100px"
android:layout_height="100px"
android:id="#+id/toButton"
android:layout_above="#+id/imageViewR"
android:layout_alignLeft="#+id/picButton"
android:layout_alignStart="#+id/imageViewL"
android:background="#drawable/fbfriends2"
android:layout_alignRight="#+id/imageViewLL"
android:layout_alignEnd="#+id/imageViewLL"
android:layout_marginBottom="20dp" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/sendButon"
android:background="#drawable/go"
android:layout_alignTop="#+id/toButton"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/plusButtonL"
android:background="#drawable/plusp"
android:layout_alignTop="#+id/videoButton"
android:layout_toRightOf="#+id/imageViewLL" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/minusButtonR"
android:background="#drawable/minusp"
android:layout_alignTop="#+id/videoButton"
android:layout_toLeftOf="#+id/imageViewRR" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/plusButton"
android:background="#drawable/plusp"
android:layout_alignTop="#+id/videoButton"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/minusButton"
android:background="#drawable/minusp"
android:layout_alignTop="#+id/videoButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="300dp" />
</RelativeLayout>
I'm adding the GridView programmatically:
gv=new GridView(ma);
List<Student> hhh=new ArrayList<Student>();
if (FriendPickerApplication.selectedUsers!=null) {
if (FriendPickerApplication.selectedUsers.size() > 0) {
for (GraphUser gu : FriendPickerApplication.selectedUsers) {
hhh.add(new Student("name", gu.getId()));
}
}
}
StudentAdapter sta=new StudentAdapter(ma,hhh);
//gv=(GridView)pView.findViewById(R.id.gridView2);
gv.setVisibility(View.VISIBLE);
MainActivity.wantedPicSize=ma.screenWidth/12; //6
int wantedSize=MainActivity.wantedPicSize+2; //10
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
relativeParams.addRule(RelativeLayout.LEFT_OF, btnSend.getId());
relativeParams.addRule(RelativeLayout.RIGHT_OF,picFriends.getId());
relativeParams.addRule(RelativeLayout.ALIGN_TOP, picFriends.getId());
relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, picFriends.getId());
gv.setLayoutParams(relativeParams);
gv.setPadding(5,0,5,0);
((RelativeLayout)pView.findViewById(R.id.rID)).addView(gv);
ViewGroup.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);//gv.getLayoutParams();
relativeParams.height = wantedSize+(int)(wantedSize/5); //this is in pixels
relativeParams.width = (int)(ma.screenWidth/3.0);//gv.getLayoutParams().width; //(int)( ( ((ma.screenWidth*3)/4)/wantedSize )*wantedSize );
gv.setColumnWidth(wantedSize); //+width betwen profiles
gv.setVerticalSpacing(5);
//gv.setNumColumns((int)((screenWidth/2)/100));
gv.setNumColumns((relativeParams.width/wantedSize));
System.out.print("COLUMNSSSSSSSSSS- "+(relativeParams.width/wantedSize));
gv.setLayoutParams(relativeParams);
gv.setVisibility(View.VISIBLE);
gv.setAdapter(sta);
Your problem here is the popup window.
There is no way to make it go under the actionbar since the actionbar is displayed in another window that is below the new window you are creating. moreover using a popup window for that complex layout is never going to perform efficiently. Have you thought of wrapping your map and the layout you are putting in the popup window in a custom layout? That would probably be the easier solution
I agree with the answer posted by Pasquale Anatriello. Though u can
You can try different methods :
mPopUpWindow.showAsDropDown(anchor);
mPopUpWindow.showAsDropDown(anchor, xoff, yoff);
mPopUpWindow.showAtLocation(parent, gravity, x, y);
I suggest you should let popUp draw only after Action Bar, take y axis offset and gravity top, say: yOffset is Equivalent to actionbar height, if you have action bar ~ height x 10% of device height , [layout_weight = 1.0].
Even if it didn't work out create a custom View [say Linear Layout] that appears and disappears and acts like popup a window and give u flexibility as u want,handle clicks by yourself, make it like a toggle, see code for animation::
Animation fadeInAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_in);
fadeInAnimation.setDuration(10);
v.startAnimation(fadeInAnimation);
Animation fadeOutAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_out);
fadeOutAnimation.setDuration(10);
v.startAnimation(fadeOutAnimation);
I'm trying to align the seekbar to the top of a view, but i can't center it with the thumb.
Is there some kind of "alignCenter" with the RelativeLayout children.
Here's a sample of my xml code :
<RelativeLayout
android:id="#+id/rl_fragment_audio_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_transparent"
android:padding="5dp"
android:visibility="gone" >
<TextView
android:id="#+id/tv_fragment_audio_begin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/tv_fragment_audio_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_fragment_audio_play"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="#drawable/btn_play"
android:visibility="gone" />
</RelativeLayout>
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_above="#id/rl_fragment_audio_player" />
For example, Google Play Music does it.
As you said the height of your seekbar might vary, unless you specify it different. Here is how you can make sure it fits all, always.
android:layout_above="#id/rl_fragment_audio_player"
is setting your seekbar bottom above rl_fragment_audio_player top. There is no direct method to specify centerAlignWith but I would remove the space it occupies within it's parent. To know the height of the seekbar you must wait until the global layout has changed. This code should be placed inside your onCreateView
sb = (SeekBar) rootView.findViewById(R.id.sb_fragment_audio);
sb.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener(){
#Override
public void onGlobalLayout() {
sb.getViewTreeObserver().removeOnGlobalLayoutListener(this);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) sb.getLayoutParams();
params.setMargins(0, - sb.getHeight() / 2, 0, - sb.getHeight() / 2);
sb.setLayoutParams(params);
// I suggest you set the seekbar visible after this so that it won't jump
}
});
The last view in the xml will be in the front. Therefore make sure your seekbar is added after the the other views. Like this
<RelativeLayout
android:id="#+id/rl_fragment_audio_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
// your bottom panel
</RelativeLayout>
<View
android:id="#+id/image_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/rl_fragment_audio_player" />
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/image_above" />
Have you tried adding a negative margin to the seekbar?
<SeekBar
android:id="#+id/sb_fragment_audio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginBottom="-15dp"
android:layout_above="#id/rl_fragment_audio_player" />
I have a Relative Layout in my xml,I want to move that view to complete left like an animation(upto screen left). I want the complete inner layout to move like an animation upto screen end
I want to put animation for Relative layout with id="center"
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/img_1"
android:layout_centerInParent="true"
android:id="#+id/cartoon_image">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/play_btn"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:id="#+id/play_btn"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:gravity="center"
android:background="#drawable/circle"
android:id="#+id/center">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/like_small"
android:id="#+id/like_image_centre"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_below="#+id/like_image_centre"
android:text="36"
android:textSize="25dp"
android:textColor="#DF013A"
android:id="#+id/likes_count_centre"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Please help in solving this issue
try this code in onCreate of your activity
by changing this functionTranslateAnimation(fromX,toX,fromY,toY) ,you can set the Animation you want to move the layout.
RelativeLayout mLayout = (RelativeLayout) findViewById(R.layout.center);
TranslateAnimation anim=new TranslateAnimation(0,80,0,0);
anim.setDuration(1500);
anim.setRepeatCount(Animation.INFINITE);
// anim.setRepeatMode(Animation.INFINITE);
anim.setRepeatMode(Animation.REVERSE);
mLayout.setAnimation(anim);
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>
I am creating a custom dialog in my app and it looks fine in the Layout Editor, but is not the right size on the device. Here's the layout for the dialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/dialog_border"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:src="#drawable/wifi" />
<TextView
android:layout_height="wrap_content"
android:id="#+id/heading"
android:layout_below="#+id/image"
android:layout_width="wrap_content"
android:layout_margin="10dp"
android:layout_alignLeft="#+id/cancel_button"
android:layout_alignRight="#+id/continue_button"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/lost_connection"
android:layout_centerHorizontal="true" />
<TextView
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_below="#+id/heading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerHorizontal="true"
android:layout_alignLeft="#+id/cancel_button"
android:layout_alignRight="#+id/continue_button"
android:gravity="center"
android:layout_margin="10dp"
android:text="#string/try_again" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/cancel_button"
android:layout_below="#+id/description"
android:layout_centerHorizontal="true"
android:id="#+id/dismiss_button"
android:text="#string/dismiss" />
</RelativeLayout>
This is what it looks like in the Layout Editor:
But this is what it looks like on the device:
It has that weird bit of extra space at the top and right side and the button is compress vertically.
That blank area is the dialog title. It can be turned off when creating the DialogFragment as:
DialogFragment df = new MyDialogFragment();
df.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
df.show(ft, "dialog");
Where the 0 in set style lets the platform choose an appropriate style and "dialog" is whatever tag you'd like to set for your dialog fragment.
I think that extra weird space at the top is the place for the dialog title. As i see on the screenshots you used a dialog and inflated a custom view into that dialog ?
I guess worth a try to hide the title of the dialog with yourDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);