speirs23 February 2016

Can't align element with toStartOf in a RelativeLayout

Basically I have a NumberPicker aligned right, an ImageView aligned top left, and two buttons in a LinearLayout container that I am trying to align to the left of the Picker and bottom of the parent. No success. The container just takes up the whole space by overlapping the picker.

<RelativeLayout
    android:id="@+id/cell_1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:animateLayoutChanges="true"
    android:background="@color/blue_light"
    android:padding="@dimen/spacing_tiny">

    <NumberPicker
        android:id="@+id/np_1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_margin="@dimen/spacing_tiny"
        android:visibility="visible" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_margin="@dimen/spacing_tiny" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toStartOf="@+id/np_1"
        android:orientation="vertical"
        android:visibility="visible">

        <Button
            style="@style/LargeHoloButton.SecondaryButton"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="@dimen/spacing_tiny"
            android:layout_weight="1"
            android:minWidth="0dp"
            android:text="@string/button.updown" />

        <Button
            style="@style/LargeHoloButton.SecondaryButton"
            android:layout_width="match_parent"
            android:layout_heigh        

Answers


Zahan Safallwa February 2016

Starting from API level 17 you cannot use layout_toStartOf. You should use

android:layout_toLeftOf="@+id/np_1"

Again from API 17 you cannot use 'layout_alignParentEnd'. Instead use

android:layout_alignParentRight="true"

And you have an error your relativelayout width is set to '0dp'. make it match_ parent.

The corrected code is below for you

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cell_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:animateLayoutChanges="true"
android:background="#000099"
android:padding="8dp">

<NumberPicker
    android:id="@+id/np_1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_margin="8dp"
    android:visibility="visible" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:src="@mipmap/ic_launcher"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_above="@+id/linearLayout"
    android:layout_toLeftOf="@+id/np_1"
    android:layout_toStartOf="@+id/np_1" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/np_1"
    android:orientation="vertical"
    android:visibility="visible"
    android:id="@+id/linearLayout">

    <Button

        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:minWidth="0dp"
    

Post Status

Asked in February 2016
Viewed 3,995 times
Voted 10
Answered 1 times

Search




Leave an answer