I am trying to arrange this layout so that the textview is positioned at the top of imageView7 but the app keeps crashing with error:
java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
Any help resolving this much appreciated
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.mattblack.fibreapp.offers"
android:background="#000000">
<ImageView
android:layout_width="fill_parent"
android:layout_height="230dp"
android:id="#+id/imageView6"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/mainimage"
android:scaleType="fitXY" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#+id/imageView6"
android:layout_centerHorizontal="true"
android:background="#000000"
android:id="#+id/frameLayout7">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Todays Offers"
android:id="#+id/textView9"
android:layout_gravity="center"
android:textColor="#ffffff"
android:textSize="40sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#ffffff"
android:layout_gravity="bottom"
android:id="#+id/frameLayout8"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/home"
android:id="#+id/button13"
android:layout_gravity="left|center_vertical"
android:background="#ffffff"
android:onClick="goHome" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/code"
android:id="#+id/button14"
android:layout_gravity="right|center_vertical"
android:background="#ffffff"
android:onClick="goProfile" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OFFERS"
android:id="#+id/button15"
android:layout_gravity="center"
android:background="#ffffff"
android:onClick="showOffers" />
</FrameLayout>
<ListView
android:id="#+id/listViewOffers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/frameLayout8"
android:layout_below="#+id/frameLayout7"
android:background="#color/cardview_light_background"
android:scrollbars="none"
android:textAlignment="center"
android:visibility="visible" />
<FrameLayout
android:id="#+id/offerBoxView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.7"
android:background="#android:color/black">
</FrameLayout>
<ImageView
android:id="#+id/imageView7"
android:layout_width="336dp"
android:layout_height="365dp"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="visible"
app:srcCompat="#drawable/boxaffiliates" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginTop="#+id/imageView7"
/>
</FrameLayout>
</RelativeLayout>
You error is probably caused by this line :
android:layout_marginTop="#+id/imageView7"
In order to achieve the desired functionality you can use LinearLayout. Put your imageView7 and textView11 in a LinearLayout with vertical gravity.
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"/>
<ImageView
android:id="#+id/imageView7"
android:layout_width="336dp"
android:layout_height="365dp"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="visible"
app:srcCompat="#drawable/boxaffiliates" />
</LinearLayout>
Or RelativeLayout with using the attribute layout_below :
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"/>
<ImageView
android:id="#+id/imageView7"
android:layout_width="336dp"
android:layout_height="365dp"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="visible"
android:layout_below="#id/textView11"
app:srcCompat="#drawable/boxaffiliates" />
</RelativeLayout>
Your textview11 having wrong value of marginTop give that margin in dimensions you gave the id of other one
android:layout_marginTop="70dp"
like this
Related
I am working on an android app where I want to align 2 linear layouts in a row with image view in between these 2 layouts.I am not able to use android studio layout editor to achieve this.
Code for the layout is:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#color/colorPrimary">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner"
android:orientation="vertical"
android:layout_marginEnd="17dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true">
<TextView
android:text="DEFG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_gravity="center"
/>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView16"
tools:text="1250"
android:textSize="30sp"
android:textColorLink="?attr/colorBackgroundFloating" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/rounded_corner"
android:layout_marginEnd="30dp"
android:layout_toStartOf="#+id/profile_image">
<TextView
android:text="ABCD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_gravity="center"
/>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView13"
tools:text="1250"
android:textSize="30sp"
android:textColorLink="?attr/colorBackgroundFloating" />
</LinearLayout>
<ImageView
android:id="#+id/profile_image"
android:layout_width="60dp"
android:src="#drawable/face"
android:layout_height="60dp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"/>
</LinearLayout>
Current Output:
Expected Output:
2 linear layouts in a row with Image view at the center of a relative layout (With Green background)
Am I doing something wrong with the arrangement of layout? How to implement such scenario?
Change the RelativeLayout to LinearLayout (Horizontal)
set width to 0dp and weight to 1 thus they will have the same width. And use gravity to put things in the center
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#color/colorPrimary">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#drawable/rounded_corner"
android:orientation="vertical"
android:layout_marginEnd="17dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:text="DEFG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_gravity="center"
/>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView16"
tools:text="1250"
android:textSize="30sp"
android:textColorLink="?attr/colorBackgroundFloating" />
</LinearLayout>
<ImageView
android:id="#+id/profile_image"
android:layout_width="0dp"
android:src="#drawable/rounded_corner"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/rounded_corner"
android:layout_marginEnd="30dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:text="ABCD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_gravity="center"
/>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView13"
tools:text="1250"
android:textSize="30sp"
android:textColorLink="?attr/colorBackgroundFloating" />
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"/>
</LinearLayout>
By using weight to the LinearLayout you can achieve this.
Check this code, but before copy pasting learn the logic of weight in LinearLayout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#ffffff"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/rounded_corner" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="DEFG" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView8"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColorLink="?attr/colorBackgroundFloating"
android:textSize="30sp"
tools:text="1250" />
</RelativeLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center">
<ImageView
android:id="#+id/profile_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable/face" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/rounded_corner" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="ABCD" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColorLink="?attr/colorBackgroundFloating"
android:textSize="30sp"
tools:text="1250" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout>
I trying to add a LinearLayout under the listView but it has a space between ListView and the LinearLayout.How to remove it ? Thanks a lot.
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ImageView
android:src="#drawable/expenses"
android:layout_marginTop="50dp"
android:layout_width="130dp"
android:layout_height="210dp"
android:id="#+id/imageView"
android:gravity="center"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="You haven't added any expenses yet"
android:textSize="15dp"
android:textColor="#color/btn_login"
android:gravity="center"
android:id="#+id/NoData"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView"/>
<Button
android:layout_width="250dp"
android:layout_height="60dp"
android:text="Add Expenses"
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:layout_below="#+id/NoData"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/listview"
android:footerDividersEnabled="false"
android:layout_weight="1"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="#color/light_gray"
android:orientation="horizontal"
android:id="#+id/linearLayout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_marginLeft="100dp"
android:id="#+id/Remaining"
android:paddingTop="10dp"
android:textSize="20sp"
android:layout_width="90dp"
android:layout_height="40dp"
android:text="Balance : " />
<TextView
android:layout_marginLeft="10dp"
android:id="#+id/balance"
android:paddingTop="10dp"
android:textSize="20sp"
android:layout_width="79dp"
android:layout_height="40dp"
android:text="balance " />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Below show my image
You need to remove this attribute android:paddingBottom="#dimen/activity_vertical_margin"
so it should look like this
<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"
tools:context=".MainActivity">
paddingBottom will place a gap between your parent relative layout and the bottom of the screen
remove this attribute android:paddingBottom="#dimen/activity_vertical_margin"
<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"
tools:context=".MainActivity">
<ImageView
android:src="#drawable/expenses"
android:layout_marginTop="50dp"
android:layout_width="130dp"
android:layout_height="210dp"
android:id="#+id/imageView"
android:gravity="center"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="You haven't added any expenses yet"
android:textSize="15dp"
android:textColor="#color/btn_login"
android:gravity="center"
android:id="#+id/NoData"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView"/>
<Button
android:layout_width="250dp"
android:layout_height="60dp"
android:text="Add Expenses"
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:layout_below="#+id/NoData"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/listview"
android:footerDividersEnabled="false"
android:layout_weight="1"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="#color/light_gray"
android:orientation="horizontal"
android:id="#+id/linearLayout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_marginLeft="100dp"
android:id="#+id/Remaining"
android:paddingTop="10dp"
android:textSize="20sp"
android:layout_width="90dp"
android:layout_height="40dp"
android:text="Balance : " />
<TextView
android:layout_marginLeft="10dp"
android:id="#+id/balance"
android:paddingTop="10dp"
android:textSize="20sp"
android:layout_width="79dp"
android:layout_height="40dp"
android:text="balance " />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
The white space on the bottom is created at the very beginning of your code.
To get rid of it remove the following from your Relative Layout.
android:paddingBottom="#dimen/activity_vertical_margin"
I am using scrollview on my activity. The scrollview contains a LinearLayout and some other views inside that layout. There is another LinearLayout android:id="#+id/linLayoutImagesContainer" used to put images items with 3 images dynamically just like in Gridview with three columns.
All other things are working perfectly. But, If I add more than 12 rows (i,e.36 images) into LinearLayout dynamically then the scrollview becomes blank with no view.
Can anybody help me? Thanks in advance.
My xml layout:
<?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">
<RelativeLayout
android:id="#+id/relLayoutActionBar"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/background_action_bar">
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Activity Detail"
android:textColor="#ffffff"
android:textSize="20sp"/>
<ImageView
android:id="#+id/ivButtonBack"
android:layout_width="35dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/back_icon"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="14sp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutTripBanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relLayoutActionBar">
<ImageView
android:id="#+id/imageViewActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:background="#drawable/default_activity_banner"/>
<!--<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#null"/>-->
</RelativeLayout>
<ScrollView
android:id="#+id/parallaxScroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_below="#+id/relLayoutActionBar"
android:layout_above="#+id/relLayoutActionFooter">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="220dp">
<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#null"
android:layout_marginTop="-220dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:alpha="0.9">
<TextView
android:id="#+id/textViewTripDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="10dp"
android:alpha="0.9"
android:background="#ffffffff"
android:text="Activity (Description)"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="10dp"
android:background="#drawable/layout_round_border">
<TextView
android:id="#+id/textViewImages"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="Images (0)"
android:textSize="18sp"
android:textColor="#android:color/white"
android:background="#drawable/layout_left_round_colored"
android:layout_toLeftOf="#+id/viewDate"
/>
<View
android:id="#+id/viewDate"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/textViewVideos"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignEnd="#id/textViewImages"
android:gravity="center"
android:text="Videos (0)"
android:textColor="#ffec6221"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/viewDate"/>
</RelativeLayout>
<LinearLayout
android:id="#+id/linLayoutImagesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relLayoutActionBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/background_action_bar">
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Activity Detail"
android:textColor="#ffffff"
android:textSize="20sp"/>
<ImageView
android:id="#+id/ivButtonBack"
android:layout_width="35dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/back_icon"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="14sp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutTripBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:background="#drawable/default_activity_banner"/>
</RelativeLayout>
<ScrollView
android:id="#+id/parallaxScroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="220dp">
<Button
android:id="#+id/buttonActivityBanner"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#null"
android:layout_marginTop="-220dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:alpha="0.9">
<TextView
android:id="#+id/textViewTripDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="10dp"
android:alpha="0.9"
android:background="#ffffffff"
android:text="Activity (Description)"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="10dp"
android:background="#drawable/layout_round_border">
<TextView
android:id="#+id/textViewImages"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="Images (0)"
android:textSize="18sp"
android:textColor="#android:color/white"
android:background="#drawable/layout_left_round_colored"
android:layout_toLeftOf="#+id/viewDate"
/>
<View
android:id="#+id/viewDate"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/textViewVideos"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignEnd="#id/textViewImages"
android:gravity="center"
android:text="Videos (0)"
android:textColor="#ffec6221"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/viewDate"/>
</RelativeLayout>
<LinearLayout
android:id="#+id/linLayoutImagesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
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.
I am making a layout for my application and I encounter the following problem.
In my layout file
But when I put it in my Fragment (via a ListView, or just with , it looks like this:
category.xml (template to populate ListView afterwards)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/second_grey">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:id="#+id/categoryName"
android:text="#string/sport"
android:textSize="24sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="12dp"
android:id="#+id/button"
android:text="#string/see_more"
android:textSize="12sp"
android:background="#drawable/blue"
android:textColor="#android:color/white" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="0.99">
<RelativeLayout
android:layout_height="wrap_content"
android:background="#drawable/card"
android:layout_width="0dp"
android:layout_weight="0.33">
<com.favega.groups.SquareLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imgContainer1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="#+id/img1"
android:src="#drawable/img_football" />
</com.favega.groups.SquareLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/football"
android:padding="8dp"
android:id="#+id/tv1"
android:layout_below="#+id/imgContainer1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:background="#drawable/card"
android:layout_width="0dp"
android:layout_weight="0.33">
<com.favega.groups.SquareLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imgContainer2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="#+id/img2"
android:src="#drawable/img_football" />
</com.favega.groups.SquareLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/basketball"
android:padding="8dp"
android:id="#+id/tv2"
android:layout_below="#+id/imgContainer2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:background="#drawable/card"
android:layout_width="0dp"
android:layout_weight="0.33">
<com.favega.groups.SquareLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imgContainer3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="#+id/img3"
android:src="#drawable/img_football" />
</com.favega.groups.SquareLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tennis"
android:padding="8dp"
android:id="#+id/tv3"
android:layout_below="#+id/imgContainer3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#color/second_grey"
tools:context="com.favega.groups.MainActivity$CategoryFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/category"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"></include>
Try this.. Use TextView instead of Button if you use Button defaultly it'll take much of size
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="12dp"
android:id="#+id/button"
android:text="see_more"
android:textSize="12sp"
android:background="#drawable/blue"
android:textColor="#android:color/white" />
Remove padding from relative layout of fragment_main.xml