Unwanted space between two layouts in android - android

Hi
I have designed a layout, i have attached a screen shot of it. I was getting an unwanted space between linear layout(tabsFragmentll) and grid view linear layout, so to remove the space i added a tag in linear layout grid view as android:layout_marginTop= "-10dp".
After adding the tag, it removed the space between the linear layout(tabsFragmentll) and grid view linear layout, but at the bottom of the screen i am getting an unwanted space which is shown at the bottom of the screen.
I am trying hard to remove the unwanted spaces, but am not able to do so. Please look in to it and give me your suggestions.
The following is my layout design code:
<LinearLayout
android:id="#+id/slide_show_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.7" >
<FrameLayout
android:id="#+id/slide_show_fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabsFragmentll"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
<fragment
android:name="com.beverly.fragments.TabsButtonFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginTop="-10dp"
android:layout_weight="1.15"
android:baselineAligned="false" >
<RelativeLayout
android:id="#+id/center_pane_rl"
android:layout_width="200dp"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/center_pane_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/places_list_view_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/tab_fragment_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TableRow
android:id="#+id/tableRowBtns"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#drawable/toolbar_background" >
<FrameLayout
android:id="#+id/checkinframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/checkInIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/checkin" />
<TextView
android:id="#+id/checkInTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/checkin"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/cameraframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/cameraIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/camera" />
<TextView
android:id="#+id/cameraTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/camera"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/photosframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/photosIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/photos" />
<TextView
android:id="#+id/photosTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/photos"
android:textSize="14sp" />
</FrameLayout>
<FrameLayout
android:id="#+id/termsframe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true" >
<ImageButton
android:id="#+id/termsIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/terms" />
<TextView
android:id="#+id/termsTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:text="#string/terms"
android:textSize="14sp" />
</FrameLayout>
</TableRow>

Related

Implementing ScrollView Android?

I've got one question. I designed layout for movie details and it looks like this:
Now, I want to add movie description when user scroll down (so this layout stays the same, but when user scrolls it will display movie description).
Current layout is wrapped in LinearLayout (vertical).
How could I implement that scroll ? I tried to add scroll view as parent but it stretches this layout down...
Here is code by now ...
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="#+id/iv_backdrop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:scaleType="centerCrop" />
<LinearLayout
android:id="#+id/layout_favorite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-40dp"
android:gravity="right">
<RelativeLayout
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_marginEnd="25dp">
<ImageView
android:id="#+id/iv_background_favorite"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:tint="#000000"
app:srcCompat="#drawable/ic_ellipse" />
<ImageView
android:id="#+id/iv_foreground_favorite"
android:layout_width="65dp"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
app:srcCompat="#drawable/ic_favorite_border_white_36px" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_short_desc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="-20dp"
android:layout_weight="4">
<ImageView
android:id="#+id/iv_poster"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginStart="20dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:textSize="19sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_tagline"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/tv_movie_released"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="12-12-2007(Released)"
android:textAlignment="viewStart"
android:textAllCaps="false"
android:textSize="16sp" />
<TextView
android:id="#+id/tv_movie_duration"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="Duration - 90 min"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/v_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/hexagon" />
<TextView
android:id="#+id/tv_vote_average"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:id="#+id/tv_number_votes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:adjustViewBounds="true"
android:src="#drawable/theatre" />
<TextView
android:id="#+id/tv_genre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/circle_double_border" />
<TextView
android:id="#+id/tv_popularity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Popularity"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/circle_double_border" />
<TextView
android:id="#+id/tv_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Language"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
For Your Description only, simply use a NestedScrollView. Make sure that the height and width of NestedScrolllView are the ones that you originally used for your description TextView. Then Simply place the TextView in the NestedScrollView.
Read more about nestedScrollView here
https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html
http://www.devexchanges.info/2016/07/nested-scroll-views-in-android.html
Use something like this
<ScrollView> //Should be on top
<RelativeLayout> //Scroll View Contains only child view
<RelativeLayout>
//Paste your whatever so far created views.
</RelativeLayout>
<RelativeLayout>
//Place your Description view here
</RelativeLayout>
</RelativeLayout>
</ScrollView>

Align android layout with equal margin

I am adding a footer to my app which will contain three buttons with image. I want similar to below view. I have tried android:layout_gravity="right/left/center" but seems not working.
Below is my XML
<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"
>
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="right"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/shops"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="shops"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="coupons"
/>
</LinearLayout>
</LinearLayout>
Try Something like this,
LinearLayout(Horizontal)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)
- LinearLayout(Vertical)
- ImageView (for the image)
- Textview (for title)
Your parent LinearLayouthave android:weightSum="4" and your child LinearLayout all sum is 3.
so change your parent LinearLayout weightSum android:weightSum="4" to android:weightSum="3".
Update :
add this way
<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"
>
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons"
android:layout_gravity="center_horizontal"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
</LinearLayout>
Try this. I think it will solve your problem.
Please try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/brands" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="brands" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/stores" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stores" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/coupons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupons" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Give equal weight to layouts
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="24dp"
android:src="#android:drawable/ic_menu_rotate"
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:text="#string/description"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
change all inner layouts
android:layout_gravity="left"
android:layout_margin="10dp"//as required
and change
android:weightSum="3"
in parent layout

Embedded views layout_weight

In my app I have an actvity with following layot. And I have proplem with layout_weight. When I use weights with views that embedded in container, that also have weight parametr,wieghts of this doesn't work. Is it posible use embedded view weight in Android?
<?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:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="1"
android:background="#color/header_color"
android:orientation="horizontal" >
<View
android:id="#+id/main_backView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#null" />
<ImageButton
android:id="#+id/menuBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/appNameText"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/appNameText"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:layout_marginLeft="30px"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/menu"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/mapClickText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30px"
android:text="#string/map_text"
android:textColor="#android:color/white"
android:textSize="21sp" />
<TextView
android:id="#+id/appNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/app_name"
android:textColor="#android:color/white"
android:textSize="21sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="8" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/imagePager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="4"
android:background="#android:color/white" >
<mobi.esys.custom_components.AutoSwitchPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20px"
android:padding="2px" />
<TextView
android:id="#+id/bannerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="21sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/suggestIndicator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#color/suggestions_indicator_color" >
<TextView
android:id="#+id/suggAmount"
android:layout_width="60px"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30px"
android:background="#drawable/circle"
android:gravity="center"
android:textColor="#color/suggestions_indicator_color"
android:textSize="21sp" />
<TextView
android:id="#+id/suggText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10px"
android:layout_marginTop="6px"
android:layout_toRightOf="#+id/suggAmount"
android:text="#string/sugg"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/suggVisitText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/suggAmount"
android:layout_marginLeft="10px"
android:layout_toRightOf="#+id/suggAmount"
android:textColor="#android:color/white"
android:textSize="12sp" />
<ImageButton
android:id="#+id/arrowBtn"
android:layout_width="30px"
android:layout_height="40px"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30px"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/arrow" />
</RelativeLayout>
<GridLayout
android:id="#+id/whereTab"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:columnCount="2" >
</GridLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
<ImageView
android:id="#+id/logoImage"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/logo"
tools:ignore="ContentDescription" />
</LinearLayout>
The weight mechanism distributes any remaining space in the parent linear layout after the first layout pass. A wrap_content layout doesn't have any remaining space. For what it's worth, a ScrollView doesn't work with match_parent height either.

Menu Buttons Layout

I want to create a menu with 6 buttons that is suppose to be in this layout. Can anyone help me please?
This will give you that exact layout (I used ImageButtons in this layout)
I added the scroll view so that the menu will scroll on very small screens. You can remove that if you want.
<ScrollView 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:layout_margin="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="2" >
<ImageButton
android:id="#+id/id1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageButton
android:id="#+id/id3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<ImageButton
android:id="#+id/id5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
<ImageButton
android:id="#+id/id6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/icon" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Or you can just use a TableLayout
you can use <TableLayout> ... </TableLayout>
example: http://www.mkyong.com/android/android-tablelayout-example/

Android - part of layout not showing up

So, i got this Layout in XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/product_grid_product"
android:orientation="vertical"
android:layout_width="315dp"
android:layout_height="295dp"
android:background="#color/white"
android:contentDescription="#string/image_content_description" >
<LinearLayout
android:id="#+id/product_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp">
<LinearLayout
android:id="#+id/product_content_buttons_image"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="130dp" >
<LinearLayout
android:id="#+id/product_content_buttons"
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="match_parent" >
<ImageButton
android:id="#+id/button_discount"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#color/product_discount_gray"
android:src="#drawable/product_discount" />
<ImageButton
android:id="#+id/button_promotion"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#color/product_promotion_gray"
android:src="#drawable/product_promotion" />
<ImageButton
android:id="#+id/button_oportunity"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#color/product_oportunity_gray"
android:src="#drawable/product_oportinity" />
<ImageButton
android:id="#+id/button_new"
android:layout_width="30dp"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#color/product_new_gray"
android:src="#drawable/product_new" />
</LinearLayout>
<LinearLayout
android:id="#+id/product_content_image_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/product_content_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/product_content_details"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="#+id/product_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:textColor="#color/gray_text"
android:textSize="14sp"
android:text="Panela de Pressão" />
<TextView android:id="#+id/product_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray_text"
android:textSize="12sp"
android:text="Aço Inox, 1.5L" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="#+id/product_content_brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textStyle="bold"
android:textColor="#color/gray_text"
android:textSize="14sp"
android:text="Marca" />
<TextView android:id="#+id/product_content_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="right"
android:textStyle="bold"
android:textColor="#color/gray_text"
android:textSize="16sp"
android:text="10000,00€" />
</LinearLayout>
<!-- starting here -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/product_content_ref"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textStyle="bold"
android:textColor="#color/gray_text"
android:textSize="14sp"
android:text="Ref.: 56065196968" />
<TextView android:id="#+id/product_content_stock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="right"
android:textStyle="bold"
android:textColor="#color/gray_text"
android:textSize="14sp"
android:text="Stock [240]" />
</LinearLayout>
<!-- to here -->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/gray_lines"/>
<LinearLayout
android:id="#+id/product_buttons"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="45dp" >
<ImageButton
android:id="#+id/shopping_cart"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#color/white"
android:src="#drawable/shopping_cart" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray_lines"/>
<ImageButton
android:id="#+id/remove_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#color/white"
android:src="#drawable/remove" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray_lines"/>
<EditText
android:id="#+id/edit_quantity"
android:layout_width="50dp"
android:layout_height="match_parent"
android:singleLine = "true"
android:background="#color/white"
android:hint="0"
android:gravity="center"
android:textSize="35sp" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray_lines"/>
<ImageButton
android:id="#+id/add_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#color/white"
android:src="#drawable/add" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray_lines"/>
<Button
android:id="#+id/observations_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#color/white"
android:text="OBS."
android:textSize="25sp"
android:textColor="#color/gray_text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/gray_lines"/>
</LinearLayout>
Nevermind the harcoded strings, they're for dummy purposes.
The problem is that anything that I write between the two comments ("starting here" to "to here") is not showing up.
I've tried increasing the height of the layout but it doesn't work.
Any help, please?
The problem is that you have two LinearLayouts both having android:layout_height="match_parent", so that the first one takes all the place.
You should set android:layout_height either to a "wrap_content" or to a fixed value.
It looks like you have the non-appearing LinearLayout on the same level of the hierarchy as another LinearLayout. Both are set to match_parent and the first one is consuming the view area.
Try setting them to either fill_parent or wrap_content.

Categories

Resources