I have multiple ImageViews which are transparent and are meant to over lap one another. I am aligning then to one another but one problem presist. How can I set the order in which they are layered? Ive tried revising the code in both xml and how the images are set in the actual java code...
I have tried FrameLayout but maybe Im not using it right...here is my implementation:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".RadarActivity" >
<ImageView
android:id="#+id/imageview_topo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageview_counties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
No matter what I do...imageview_topo is always placed on top. Even in the code i have instantated topo first and retrieved its image first!
Thank you!
I referred a site here that says:
If multiple child views exist, then they are drawn, in order, one atop
the other. This means that the first view added to the frame layout
will display on the bottom of the stack, and the last view added will
display on top.
You can check this site too: http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/
May be i can help you more if you show the screenshot of your UI.
Related
Open source code that I am using
in my design render it shows me the entire background is blue but the actually app only have color on the listviews. Following is my xml code and screen shots.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
render
actually app:
I tried to change the textview layout height to match_parent, but it still didn't work, so what do i need to do to change the entire background?
Thnaks
What's happening here is that your XML file is defining the layout for an individual element in that list view, then the list view is programatically applying this XML to build a new view onto the list whenever a new BLE device is discovered. The size of each list element is defined externally, by whatever is putting each of your views into the list. Therefore, when you put match_parent in the LinearLayout and expect that to fix your issue, it does not because it only fills the area allotted by the listview. The fix is to change the background color within the listview itself, which is not done in this XML.
I'd need to see to more code to know exactly how to do this, but I am going to take a shot in the dark and assume that you are using a ListActivity, as in the Google BluetoothLeGatt example. In this case, you can change the background color of the ListView using something like:
getListView().setBackgroundColor(Color.rgb(86, 159, 238));
Placed in the onCreate method.
The view indicated is only a view inside the layout that contains the ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
You must change the background color to the layout that contains the ListView
android:background="#b8569fee"
Recently, designers in my company liked creating half-above elements in layouts for Android apps. I've been struggling for a while trying to make these elements behave as good as possible, but I'm already tired of it. Is there any way of positioning views like on this image
with an assumption that if user touch row/card it became "checked" and this black dot icon became visible (second click makes it invisible of course).
You can do something like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/circle_view"
android:background="#android:color/holo_blue_bright">
<android.support.v7.widget.CardView
android:id="#+id/second_view"
android:layout_width="100dp"
android:layout_height="match_parent"/>
</FrameLayout
<View
android:id="#+id/circle_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#android:color/holo_red_dark"
android:layout_marginEnd="-8dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
second_view is endOf circle_view so if circle_view is gone second_view will align to startOf parent.
circle_view should have marginEnd set to negative value of its width divided by two
I have the Views attached to each other in the following order:
Activity->RelativeLayout->RelativeLayout->Text
When I change the Y of one of the Text attached to the inner RelativeLayout, parts of it are cut.
Here's a screenshot:
http://s28.postimg.org/ypmvrjz25/image.png
I'm coding purely in Java, no XML.
What's going on?
It looks like one layout is overlapping on another because the menu bar is pushing it down. If you just want the text centered I would suggest setting that in the parameters like so.
android:gravity="center"
This places the text in the center if that is what you want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView12"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
As #Jonathan Whalen suggested you probably have some overlap, I suggest you to change your relative layouts background color to see wich one is overlapping the text. Also try to not use fixed height for the layouts but use wrap_content instead, as fixed dims are frequently the cause of layouts overlap.
OK, Im starting to get the hang of how XML operates with the Android interface, but I've ran into a problem...
I just have a HorizontalScrollView with a RelativeLayout inside to which I will place other views later. The HorizontalScrollView as you can see is sitting above a button, and below another button. I like where its placed, but I dont want it exactly right above and below the buttons. I would like some spacing (padding). Ive tried adding padding but it seems to have no effect...
Heres my attempted XML:
<HorizontalScrollView
android:id="#+id/scrollview_xyzInfo"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_above="#+id/button_refresh"
android:layout_alignParentRight="true"
android:layout_below="#+id/button_mySettings"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:background="#drawable/refresh_selector" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</RelativeLayout>
</HorizontalScrollView>
Any help would be much appreciated :-)
Nevermind! Use margins when seperating two views like so:
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
Answer Found at:
Padding not working Android
Padding and margin works only with LinearLayout. Which layout are you using?
My app requires the ability to add several views on one line in a user selected order.
I found this tutorial which seems to accomplish what I want with a bit of modification.
http://www.androidpeople.com/android-custom-listview-tutorial-example/
Having followed the tutorial and made the required changes, the code works except for one strange issue. The position increments but when it hits ~9 it returns to zero and then re-adds views that are already in the list and thus never reaches the >9 ones.
Also, if I scroll down to the bottom and then back up the very first entry has changed! It may change more but I haven't checked that.
Through some tests I have discovered that the textSize has some effect. If I set it small enough so that all 'rows' will show on screen at once then they appear fine.
This is my listview layout that gets inflated into the main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="60dip"
style="#style/DefaultTheme">
<TextView
android:id="#+id/Line01"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#F00" />
<TextView
android:id="#+id/Line02"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#0F0" />
<TextView
android:id="#+id/Line03"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#00F"
android:layout_marginRight="5dip"/>
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="2dip">
<TextView android:id="#+id/Name"
android:text="Name"
style="#style/Name" />
<TextView
android:id="#+id/Status"
android:text="Status"
style="#style/Status" />
</LinearLayout>
<ImageView
android:id="#+id/StatusImage"
style="#style/StatusImage" />
</LinearLayout>
I change background colours and text but that is all. Any ideas what is the problem?
Thanks!
That's because ListView recycles Views. It creates as many Views as required then the one which isn't available will be recycled as next.
So you have to set the colors/attributes in the getView or bindView methods of the adapter.
And btw. what you posted doesn't inflate the ListView, as there is no `' object in it. At best it could be a single ListView item, but not the listview itself ^^
I feel dumb for asking this now and not going back over the tutorial completely.
I was setting the values in my layout I place in the ListView on my main layout only when a new ViewHolder was created. Thus when I scrolled, the views were recycled, but never updated with the correct View settings.
All working fine now!
Cheers