I trying to create a relative layout that look like toolbar but I keep on having such height problem as shown below:
What I want is:
Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/Searchtoolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="#color/Toolbar_default_color"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_below="#+id/Searchtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/FilterLayout"
android:layout_width="match_parent"
android:layout_height="40dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/search_filter_icon"
android:background="#drawable/search_filter_bgn_btn"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<ListView
android:id="#+id/feed_listview"
android:layout_below="#+id/FilterLayout"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
</RelativeLayout>
</RelativeLayout>
In your ImageButton use: android:layout_height="match_parent"
instead of android:layout_height="wrap_content"
Or resize your Image using photoshop or any other free tool to fit 40dp exactly.
WRAP_CONTENT: which means that the view wants to be just big enough to enclose its content (plus padding)
What you need:
MATCH_PARENT: which means that the view wants to be as big as its parent (minus padding)
Documentation.
I found my bad and silly mistake. It was the "android:layout_marginTop="?attr/actionBarSize" under the listview that causes the white layout to be extended. After I removed that line, I got what I wanted. =)
Related
I am a new user in Android dev. Actually I have one problem that I can't solve for much time.
I have a layout with Scroll View, there are ImageView and TextView in this ScrollView. You can see it in my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity ="center"
android:fillViewport="true"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:padding="10dp"/>
<TextView
android:id="#+id/textInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I take the data from JSON and using this layout for input it in.
There are images that have different forms.
So, please, help me with it. What I must to do with layout markup and what scaleType I must to use.
Thanks in advance.
P.S. Sorry for my English)
It would be helpful if you posted the code that takes the data from a json too.
For picking the right scaletype, this might help.
Hello) I have already solve my problem. I need only to add this things
android:scaleType="fitCenter"
android:adjustViewBounds="true"
I just forgot what adjustViewBounds do)
how to anchor a view in front of the toolbar?
please help me like this.
indeed I wish to place this half circle above the toolbar as shown below
Try this way
<?xml version="1.0" encoding="utf-8"?>
<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="#ffaa">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:id="#+id/toolbar">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/semicircle"
android:layout_marginTop="-170dp"/>
</LinearLayout>
output:
Keep layout_marginTop for image view as per your convenience
I have a view which contains a top view (it's a mapview but it's not implemented yet) and a listview below it.
What I'm trying to do is to make the top of listview to be overlay the bottom of the top view a little bit. Here is something similar to what I'm trying to achieve :
(without the tab headers and the image will be the mapview)
I'm not sure how I can achieve that, here is what I have so far:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="10dp"
android:divider="#android:color/darker_gray">
</com.hmm.widgets.CustomListView>
</RelativeLayout>
I've tried negative margin which didn't work. I'm not sure how can I achieve something similar. Should I be using FrameLayout?
You can use LinearLayout in your case and design the layout like this. This is a trick of setting a negative layout_marginTop to your custom ListView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/activity_vertical_margin"
android:dividerHeight="10dp"
android:layout_marginTop="-40dp"
android:divider="#android:color/darker_gray">
</com.hmm.widgets.CustomListView>
</LinearLayout>
Complementing Reaz's answer, you can do it with RelativeLayout too without using negative margins (which are a bit controversial).
Note the last four attributes in the CustomListView: you constraint the height with alignParent*, set a dummy height which will be discarded, and offset the view from the top with a margin. The "negative offset" will be 250dp - 200dp = 50 dp.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#android:color/holo_red_dark">
</View>
<com.hmm.widgets.CustomListView
android:id="#+id/runners_list"
android:background="#android:color/darker_gray"
android:layout_width="match_parent"
android:dividerHeight="10dp"
android:divider="#android:color/darker_gray"
android:layout_height="0dp"
android:layout_marginTop="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
</com.hmm.widgets.CustomListView>
</RelativeLayout>
I'm trying to set a analog clock for my app but both the analog clock and the digital clock just dont appear when i run the app on my device, but if i look at the graphic view of the layout its there!
Heres my code:
<?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:orientation="vertical"
android:weightSum="100" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="30" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
//Some Text Views and Edit Texts here!
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20" >
<Space
android:layout_width="match_parent"
android:layout_height="2dp" />
<Button
android:text="Send"
android:id="#+id/bSendEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="50" >
<Space
android:layout_width="match_parent"
android:layout_height="2dp" />
<AnalogClock
android:id="#+id/acClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
My guess is that your layout is not scaling well to varied resolutions. Click the Preview All Screens option (in in the Graphical Layout section of Eclipse) to see if you can see the same cropping problem there. If so, you'll need to experiment with different layout weights, etc. to ensure that the layout works well across different device resolutions.
I guess problem can be about ScrollView. Try to change it and let me know result. Because I don't know for which reason its happening but sometimes with ScrollView view is getting hidden...
I am building an app that uses this library:https://github.com/umano/AndroidSlidingUpPanel to create a panel that slides on from the bottom of the screen when a user clicks an item in a listview.
However i dont want the slide up panel to take up the entire screen. I need there to be a gap at the top, between the panel and the action bar, of exactly 80dp.
I have tried everything i can think of (putting a spacer there with a transparant background, using layoutParams (gives error), etc). But nothing seems to work.
If someone could give me some suggestions as to what i could try next, i would much appreciate it.
The xml layouts are below.
Thanks for your time.
Corey
<com.bacon.corey.audiotimeshift.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp"
sothree:overlay="true">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:id="#+id/fabbutton"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:colour="#color/holo_red_light"
app:drawable="#drawable/ic_content_new"
/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:textSize="16sp"
android:id="#+id/slideUpPanel"
android:background="#android:color/transparent"
>
<fragment android:name="com.bacon.corey.audiotimeshift.PlayFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_play"
/>
</FrameLayout>
</com.bacon.corey.audiotimeshift.SlidingUpPanelLayout>
What about wrapping your SlidingUpPanelLayout in another layout, say FrameLayout and adding some good old paddingTop to the latter?
I have found a workaround. Draw the background of the pane transparent and put a padding top, but first the library must be modified like it's written here:
https://github.com/umano/AndroidSlidingUpPanel/issues/4
Hope this helps somebody in the future :)