I got trouble with android layout in xamarin. How to fill space without overlapping the layout in android xml?
This layout confusing me. Because it's not like php or xaml. I want to make the layout view like this:
I'm using nexus 6 in design windows. When I ran the debug in emulator the view become like this:
The layout overlapping. I wonder how to fill blank space in android layout size so it can fit in my device (dynamically)?
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/main_content"
android:gravity="fill_horizontal|bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp"
android:layout_weight="1"
android:gravity="center|bottom">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:layout_marginTop="10dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="#+id/linearLayout1"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Is there something I can do?
Thanks in advance :)
Use this xaml file & compare with your file so that you will get idea what mistake you was making
I realize the issue was using android:gravity (in second & third LinearLayout) along with android:weight which was pushing your layout toward top.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/main_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:layout_marginTop="0dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="#+id/linearLayout1"
android:layout_marginTop="0dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Related
I'm trying to stack two vertical LinearLayout in LinearLayout horizontally.
My code:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtusername" />
<TextView
android:text="Date registration"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtdateregistr" />
<TextView
android:text="Phone number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtphonenumb" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="horisontal"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercountnumb" />
<TextView
android:text="Ordr"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercount" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycountnumb" />
<TextView
android:text="Delv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycount" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Also everything looks as I and has conceived:
And the scheme for full understanding:
But when I compile that in VS2015 see error "String types not allowed (at 'orientation' with value 'horisontal')". Need help
Its a typo.
Change,
android:orientation="horisontal"
to
android:orientation="horizontal"
In the root use below attribute
wheightSum="10"
and in child view use wheight = "5" for each child view
Note: on base layout use android:orientation="horizontal" for horizontal display or android:orientation="vertical" for vertical display
Error in LinearLayout orientation.It should be horizontal or remove this.(By default Linear layout has horizontal orientation. )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:text="User Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtusername" />
<TextView
android:text="Date registration"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtdateregistr" />
<TextView
android:text="Phone number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/txtphonenumb" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercountnumb" />
<TextView
android:text="Ordr"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/ordercount" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1">
<TextView
android:text="Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycountnumb" />
<TextView
android:text="Delv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/deliverycount" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have problem with implement CardView in RelativeLayout. I set CardView at back position in RelativeLayout. But it's seem not which I want.
I want like this (edited by photosop):
Current Display (on live Device and on android studio)
this the xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="#+id/root_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
card_view:cardCornerRadius="10dp"
android:layout_alignBottom="#+id/layout_isi"
android:layout_alignLeft="#+id/layout_isi"
android:layout_alignTop="#+id/layout_isi"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/layout_isi"/>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_isi"
android:layout_marginLeft="8dp"
android:layout_below="#+id/layout_business_name_child">
<android.support.percent.PercentRelativeLayout
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_widthPercent="75%">
<LinearLayout
android:id="#+id/layout_thumbnail_business"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_widthPercent="50%">
<com.kamardagang.utils.ResizeImageView
android:id="#+id/thumbnail_business"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="#drawable/placeholder" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/layout_thumbnail_business"
android:orientation="vertical"
app:layout_widthPercent="50%">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.joanzapata.iconify.widget.IconTextView
android:id="#+id/icon_status_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="#string/fa_minus_circle" />
<RatingBar
android:id="#+id/business_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="#+id/status_rating"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center"
android:padding="10dp"
android:text="status_rating" />
</LinearLayout>
<com.kamardagang.utils.TimesNewRomansTextView
android:id="#+id/business_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="#+id/business_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="business_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<com.kamardagang.utils.TimesNewRomansTextView
android:id="#+id/business_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:text="business_status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/left"
android:orientation="vertical"
app:layout_widthPercent="25%">
<com.joanzapata.iconify.widget.IconButton
android:id="#+id/count_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#337ab7"
android:text="#string/star"
android:textColor="#color/white" />
<com.joanzapata.iconify.widget.IconButton
android:id="#+id/view_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lihat_rating" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<android.support.v7.widget.CardView
android:id="#+id/layout_business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
app:cardBackgroundColor="#337ab7"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.kamardagang.utils.TimesNewRomansTextView
android:id="#+id/business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_name"
android:textColor="#color/white"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
I also implemnted View.bringToFront();, but it's not work, so how to fix it ? sory for my English
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="#+id/root_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="#+id/layout_business_name_child"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
card_view:cardCornerRadius="10dp">
<android.support.percent.PercentRelativeLayout
android:id="#+id/layout_isi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_business_name_child"
android:layout_marginLeft="8dp">
<android.support.percent.PercentRelativeLayout
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_widthPercent="75%">
<LinearLayout
android:id="#+id/layout_thumbnail_business"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_widthPercent="50%">
<ImageView
android:id="#+id/thumbnail_business"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/layout_thumbnail_business"
android:orientation="vertical"
app:layout_widthPercent="50%">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/icon_status_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="Test" />
<RatingBar
android:id="#+id/business_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center" />
<TextView
android:id="#+id/status_rating"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center"
android:padding="10dp"
android:text="status_rating" />
</LinearLayout>
<TextView
android:id="#+id/business_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/business_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="business_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/business_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="0dp"
android:text="business_status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/left"
android:orientation="vertical"
app:layout_widthPercent="25%">
<Button
android:id="#+id/count_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#337ab7"
android:text="Test"
android:textColor="#android:color/black" />
<Button
android:id="#+id/view_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/layout_business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:descendantFocusability="blocksDescendants"
app:cardBackgroundColor="#337ab7">
<TextView
android:id="#+id/business_name_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="business_name"
android:textColor="#android:color/black" />
</android.support.v7.widget.CardView>
</RelativeLayout>
I put the PercentRelativeLayout within the CardView and it worked.
Hope this helps :)
I want to create following layout.
--------------------------------
Title
Summary Info
[Get Direction][Call][More Info]
--------------------------------
I code following layout but buttons not showing. I have no idea why LinearLayout works like FrameLayout so the RelativeLayout hides buttons. Did I miss something here?
I am using support library 22.1
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
Your relative layout has been set to match_parent for it height!
change it to wrap_content
that should help you
or put it in a LinearLayout
something like this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/location_card_height">
<ImageView android:id="#+id/cardImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="vertical" >
<RelativeLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<TextView android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:singleLine="true"
android:hint="Title" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/title">
<TextView android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Info"
android:layout_alignParentRight="true"
android:ellipsize="end" />
<TextView android:id="#+id/summary"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearance"
android:singleLine="true"
android:hint="Summary"
android:layout_toLeftOf="#id/info"
android:ellipsize="end" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:id="#+id/btnDirection"
android:text="#string/get_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnCall"
android:text="#string/label_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnMoreInfo"
android:text="#string/more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
If you are fine With Linearlayout Then Here is Your XML file
<?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="1" >
<ImageView
android:id="#+id/cardImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/info"
android:layout_weight="1"
android:ellipsize="end"
android:hint="Summary"
android:singleLine="true"
android:text="Summary"
android:textAppearance="?android:attr/textAppearance" />
<TextView
android:id="#+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="right"
android:hint="Info"
android:singleLine="true"
android:text="Info"
android:textAppearance="?android:attr/textAppearance" />
</TableRow>
</LinearLayout>
<LinearLayout
android:id="#+id/panelAction"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnDirection"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get_direction" />
<Button
android:id="#+id/btnCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="call" />
<Button
android:id="#+id/btnMoreInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="more_info" />
</LinearLayout>
EDITED to improve specifics:
Hi, my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="10dp"
tools:context="${packageName}.${activityClass}" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="Select Character"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="#+id/textView1"
android:orientation="vertical"
android:paddingTop="10dp" >
<TextView
android:id="#+id/SelectedCharacterName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="#+id/TraitName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trait 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
etc...
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:fillViewport="false"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Character1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4a4a4a"
android:clickable="true"
android:gravity="center"
android:text="Character 1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
etc...
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/buttonConfirmCharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="#string/button_Confirm" />
</LinearLayout>
I am looking to make the scrollview fit the remaining space between the other elements however with this setup the scrollview doesn't seem to render at all. These settings are the result of looking for solutions and implementing weight.
An answer without java code would be preferential.
Thanks.
Here, this would works just fine
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:id="#+id/SelectedCharacterName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/TraitName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trait 1" />
etc...
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Character1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:text="Character 1" />
etc...
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/buttonConfirmCharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/button_Confirm" /></LinearLayout>
Basically it's a page of text and pics with ads at the bottom. It works fine on smaller devices like phones, but on larger like tablets there is a problem....more of a user dislike thing.
If the content of page is small then ads, which comes correctly at the end of content actually comes in the middle of the screen.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/vnaslov"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginLeft="7dp"
android:gravity="left"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:id="#+id/vautor"
android:layout_below="#+id/vnaslov"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vdatum"
android:layout_toRightOf="#+id/vautor"
android:layout_below="#+id/vnaslov"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vlid"
android:layout_below="#+id/vdatum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:layout_marginLeft="7dp"
android:textSize="16sp"
android:textStyle="bold"
/>
<com.loopj.android.image.SmartImageView
android:id="#+id/vslika"
android:layout_below="#+id/vlid"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_margin="5dp"
/>
<TextView
android:id="#+id/vtijelo"
android:layout_below="#+id/vslika"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_marginLeft="7dp"
android:textSize="16sp" />
<Button
android:id="#+id/videobutton"
android:layout_below="#+id/vtijelo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/dugme_video"/>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<com.google.ads.doubleclick.DfpAdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
</ScrollView>
It works if it's simple like this...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/wrap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="TextView"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="TextView"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/but1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="But1" >
</Button>
<Button
android:id="#+id/but2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="But2" >
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>`
But not if it's filled with my content like the above in my question. First linearlayout with content up to the ad, and second with just the ad...
How would the content inside linearlayout be a problem?
Why?
The trick is to use layout_weight="1" and fillViewport="true" on the ScrollView.
This should do the trick:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativemain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/wrap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
//put your content here
</LinearLayout>
<LinearLayout
android:id="#+id/myadv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
//this is your advertisement
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>