I need to have a dialog (it's a game dialog) where buttons are at the lower corners of the dialog. Not inside the dialog but rather on the very corners (i.e. part of the button will reside over the dialog and the part will be outside of it).
First, as far as I know you can't move layout children outside their parent.
I've never tried exactly what you're going for, but I think it can be done. The trick would be to go with an activity with a dialog theme (you can find examples of these on the developer site or the API demos). Make sure your layout's root node has width and height set to wrap_content. Your root layout should be a RelativeLayout and have NO background (android:background="#0000").
Next, add another layout to your root node (FrameLayout would probably work) with a custom drawable for a background (or use the one that the default dialog uses from the framework) and width and height set to fill_parent or match_parent. Set android:padding to some dip value which pulls the background in from the edge of the dialog.
The only thing left to do would be to add your other layout elements to the root node. The FrameLayout will be drawn beneath everything else, and the padding will create the illusion of borders which do not encompass your UI.
Update
Yikes, just tried the above with good and bad results. First, you'll definitely want to look at the "Custom Dialog" example from the API demo, which makes use of:
CustomDialogActivity.java
layout/custom_dialog_activity.xml
xml/styles.xml
drawable/filled_box
Create an activity which uses the above xml layout file, and set the style for the activity to Theme.CustomDialog that you defined in xml/styles.xml. This will get you a red background for your activity. You can then edit the filled_box shape file to just have one background attribute set to invisible ("#0000"). The result should be an dialog-shaped activity with no background.
Next I tried to hack a background using my thoughts from above. The idea should be that there's a phony background drawn behind the other UI elements which does not encompass them, so it could be "shrunk" using layout_margin and not affect them. The problem here is that the phony background needs to have width and height set to relative to the other UI elements, so it sort of HAS to encompass them, so it can properly measure its own width and height relative to them.
So I think the solution could be to do most of what I've said above, except don't try the phony background thing. Just use a 9-patch drawable for your root layout background, and shrink the edges of your background to be drawn farther in than your content. You'd still use the custom theme stuff from above with an invisible window theme.
Here is a sample layout which i tried:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:orientation="vertical"
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/dialog_frame">
</FrameLayout>
<Button android:layout_width="wrap_content"
android:id="#+id/button1"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_centerHorizontal="true"
android:text="Button"></Button>
</RelativeLayout>
here is the screenshot:
hope u get the hint , goodluck
Related
I am new to Android Studio, and no matter what I do whenever I add something such as a textview or button to it, I cannot make it the size I want it to. It always auto aligns itself to the sides or top. When I want to make a square it doesn't allow me to do it. It never allows me to put my button or textview where I want it to. How do I make it so I can place my stuff anywhere I want and whatever size I choose it to be?
You are probably using linear layout,You can use relative layout instead for start, although if you want to put a lot of buttons its getting harder to work with relative layout and linear layout is more organized go to you'r xml and there edit the in the first line where it says <LinearLayout... to <RelativeLayout> and don't forget to do the same at closing,I recommend you to watch a video on youtube on how to work with linear layouts.
In RelativeLayout, it enable the attributes like alignParentRight="true/false" for exact right position and so on...
layout_below="#id/tool/viewID_below_you_want_to_put" and same for other side
so you can use it
For Example,
<RelativeLayout
...>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_toRightOf="#id/txt1"
android:alignParentRight="true"
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
which will make your textview in left and then button in right of textview
If you want to set it in center tou can set gravity="center | center_vertical | center_horizontal"
also you can set size as you want in width or height like
android:layout_width="50dp"
So I've defined a simple Button in xml like so:
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/home_button_student"
android:textSize="#dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="#+id/home_button_student"
android:drawableLeft="#drawable/ic_action_emo_cool"/>
I have several of these in a LinearLayout and as expected they fill the screen, each taking up an equal amount of space, each one looking similar to this: http://i.imgur.com/fMNldop.jpg
The problem I'm having here is as you can see the drawable is only the same height as the text, I'd like to know if there's a way to make the drawable scale to the height of the button itself WITHOUT using a workaround like creating my own Button using another LinearLayout, I'd like to stick to using a Button.
I have different versions of the image in my res folder under the correct folders (xxhdpi, xhdpi, and so on) but it only seems to want to use the smallest one.
EDIT: It seems like this may be due to the image supplied being too small, as I said just above I have the image in a whole range of sizes, how can I tell android to use a larger one on a larger screen instead of defaulting to the smaller one? I thought that was the whole point of having multiple sizes in the first place.
The drawable will only be the size the bitmap is. Just provide larger image and it should be fine.
For that you need to change your layout_height from fill_parent to wrap_content like this
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/home_button_student"
android:textSize="#dimen/abc_text_size_headline_material"
android:onClick="buttonClick"
android:id="#+id/home_button_student"
android:drawableLeft="#drawable/ic_action_emo_cool"/>
If you want a button real big in height, then make sure you have an equal heighted drawable image.and also there's no need to give weight here,
you can use your custom layout for that like drawable left or right whatever you want just use linear layout put in this imageview and button for the view. so you can put image that you wants
I'm a beginner Android developer and I'm making my first app. I'd like to make a simple view that is overlayed on the map with a semi-transparent background. This is what it would hopefully look like:
As you can see, one of these dialogs/windows has a simple integer displayed and the other will have a rendered graph/chart.
What would be the best way to go about making this? A dialog? The problem with that might be that I would for the user to be able to work with the mapview below while this is displayed. And I'm not sure if a simple transparent rectangular canvas is the right way to get this done.
Any suggestions/ideas would be much appreciated. Thanks so much.
two ways to go
-Make it a FrameLayout so add MapFragment first then add a Linearlayout with orientation horizontal and make gravity top and translucent background,so it will be displayed on top of map, and it will also involve the elements inside,
-Instead of FrameLayout make it a RelativeLayout and the same process as above.
-Make the overlay as seperate Activity(which is the worst case scenario)
Sample code for overlay can be like this
<LinearLayout
....
android:divider=".." // some drawable or color whatever you want
android:showDividers="middle"
android:orientation="horizontal"
android:background="a000">
<TextView
....
android:value="58"/>
<com.example.custom.view
..../>
</LinearLayout>
I think you can use a RelativeLayout on the top of the MapFragment, with a black background and some opacity (for that you can use a drawable).
Then, on the RelativeLayout you can add other controls like TextView and ImageView
I don't recommand you to use a Dialog, since it sounds like it's not corresponding to your needs.
How can you create larger views than the screen real-estate in Android?
I am trying to recreate a view from my iOS project in Android. The view consists of a first column of static images and then a 20x13 grid of buttons (yes that's 260 in total!) which will generate another activity when clicked:
Each button throws out an integer and there is a daily background image change.
The problem for phones is screen real-estate. Fitting everything on one screen makes the buttons too small to touch properly. In the iPhone app I created bigger buttons set offscreen within a ScrollView that the user could then scroll to. To my knowledge Android does not do a 2d version of ScrollView. I have tried to use gridview dynamically, for example:
However, the dynamic buttons generated need to go VERTICALLY, they are too small to press on smaller screens AND it only scrolls in one direction.
I have also been thinking about 14 Vertical Linear/RelativeLayouts but again I am limited to screen dimensions which will make the buttons too small.
I did implement code from this link which works perfectly well. You create a custom scrollView and then insert it within your XML file:
<RelativeLayout
android:id="#+id/scene_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawingCacheQuality="low"
android:orientation="horizontal" >
<com.example.yourappname.TwoDScrollView
android:id="#+id/scene_scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawingCacheQuality="low" >
</com.example.yourappname.TwoDScrollView>
</RelativeLayout>
You can then put your items in a layout and be sure to sort the width/height parameters to what you need - match_parent will fix your layout to the screen.
Suppose I have made a diagram e.g a circle on android mapView. Now I want to remove/blackout/hide all other maps except that portion. I can zoom in out that portion too
Is this possible?
Best Regards
I have a similar problem of make map view inside certain area.not sure it will help you or not but you can try it.
What you should do is take image of circle(Background is Transparent) and put your image as background in Linear layout. and inside that LinearLayout you can put map view.
your xml will Look like below.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/Circle_back" >
<com.google.android.maps.MapView
android:id="#+id/whereami_mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="YOUR API KEY"
android:clickable="true" />
</LinearLayout>
</LinearLayout>
i have to view it inside rectangle box. below is the similar screen shot you will get while running. you d'nt need to hide rest of the part of Map.
hope it will help some how what are you looking for.
Make a trick
Zoom will work in your case. Set zoom level and
Use android:clickable="false" in your layout file.
;)