Create separator between button - java

I have problem with create my button separator. This my buttons layout with my xml layout my create button.
This is fragment activity_swipe.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>
but try make separator that this

Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#android:color/holo_blue_bright"
>
<Button
android:id="#+id/searchDreamButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#android:color/holo_blue_bright"
android:text="#string/search_dream"
android:textAllCaps="false"
/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/black_color"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
<Button
android:id="#+id/singInButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
/>
</LinearLayout>

try this my friend
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>

Related

How to display ImageView below TextView in LinearLayout

I'm writing a sports app and I want to place the text exactly under the picture, but I can't get it aligned. If there is a large text somewhere, then the picture is not in the middle. how to make sure that the text is always exactly under the picture, or the picture is always exactly under the text?
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#drawable/shadow_matches_background"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="190dp">
<LinearLayout
android:id="#+id/title_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:weightSum="2">
<TextView
android:id="#+id/title_team_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_weight="1"
android:fontFamily="#font/roboto_medium"
android:text="Chelsea"
android:textColor="#color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/title_team_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_weight="1"
android:fontFamily="#font/roboto_medium"
android:text="Manchester City"
android:textColor="#color/black"
android:textSize="20sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/image_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/img_team_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title_team_1"
android:src="#drawable/image_3" />
<ImageView
android:id="#+id/img_team_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_5"
tools:ignore="DuplicateIds" />
</RelativeLayout>
<TextView
android:id="#+id/date_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image_team_list"
android:layout_marginTop="5dp"
android:fontFamily="#font/roboto"
android:text="25 сентября 2021 года"
android:textAlignment="center"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/date_team_list">
<Button
android:id="#+id/btn_subscribe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00000000"
android:text="#string/btn_subscribe"
android:textColor="#color/colorMatchesBtn" />
<Button
android:id="#+id/btn_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00000000"
android:text="#string/btn_detail"
android:textColor="#color/colorMatchesBtn" />
</LinearLayout>
</RelativeLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="190dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp">
<LinearLayout
android:id="#+id/title_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
tools:ignore="DuplicateIds">
<TextView
android:id="#+id/title_team_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_weight="1"
android:fontFamily="#font/roboto_medium"
android:text="Everton"
android:textColor="#color/black"
android:textSize="20sp"
tools:ignore="DuplicateIds" />
<TextView
android:id="#+id/title_team_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_weight="1"
android:fontFamily="#font/roboto_medium"
android:text="Norvich City"
android:textColor="#color/black"
android:textSize="20sp"
tools:ignore="DuplicateIds" />
</LinearLayout>
<LinearLayout
android:id="#+id/image_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_team_list"
android:layout_marginTop="5dp"
tools:ignore="DuplicateIds">
<ImageView
android:id="#+id/img_team_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/image_3"
tools:ignore="DuplicateIds" />
<ImageView
android:id="#+id/img_team_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/image_5"
tools:ignore="DuplicateIds" />
</LinearLayout>
<TextView
android:id="#+id/date_team_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image_team_list"
android:layout_marginTop="5dp"
android:fontFamily="#font/roboto"
android:text="25 сентября 2021 года"
android:textAlignment="center"
android:textSize="15sp"
tools:ignore="DuplicateIds" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/date_team_list">
<Button
android:id="#+id/btn_subscribe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00000000"
android:text="#string/btn_subscribe"
android:textColor="#color/colorMatchesBtn"
tools:ignore="DuplicateIds" />
<Button
android:id="#+id/btn_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00000000"
android:text="#string/btn_detail"
android:textColor="#color/colorMatchesBtn"
tools:ignore="DuplicateIds" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
you should follow Constraint layout, for your desired output I have attached some code. I hope, it helps.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="#id/ivPic"
app:layout_constraintRight_toRightOf="#id/ivPic"
app:layout_constraintBottom_toTopOf="#id/ivPic"
android:text="Your desired text"
android:textColor="#color/black"
android:textSize="15sp"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
/>
<ImageView
android:id="#+id/ivPic"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/tvTitle"
android:src="#drawable/yourImage"
android:scaleType="centerCrop"
android:padding="2dp"
/>
<TextView
android:id="#+id/tvClubName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="#id/ivPic"
app:layout_constraintRight_toRightOf="#id/ivPic"
app:layout_constraintTop_toBottomOf="#id/ivPic"
android:text="Liverpool"
android:textColor="#color/black"
android:textSize="15sp"
android:singleLine="true"
android:padding="3dp"
android:gravity="center_vertical|center"
android:marqueeRepeatLimit="marquee_forever"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
And take a look at ConstrainsLayout It will help you out build more complex layouts easily.Also your list of teams is completely hardcoded you should definetely switch to RecyclerView.

How to add a scroll view in an Android app

I want to add scroll in my XML without editing the following code. Is there any way of adding it in the following XML? I tried by adding Scroll view and then linear view but it makes the view cut. Is there any way of making it better, I have searched other repository but I didn't find a solution.
<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"
tools:context=".Activity.BookSeatsActivity"
android:orientation="vertical"
android:weightSum="12"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:weightSum="5"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/wheel"
android:src="#drawable/mywheel"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid"
android:layout_marginTop="10dp"
android:layout_below="#+id/wheel"
android:padding="1dp"
android:numColumns="5"
/>
</RelativeLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:weightSum="3"
android:layout_marginEnd="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_open"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:text="Available"
android:paddingStart="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_booked"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:text="Unavailable"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/seat_selected"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:paddingStart="5dp"
android:gravity="center_vertical"
android:text="Selected"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginEnd="10dp"
android:orientation="horizontal"
android:layout_marginStart="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Seat Selected : "
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:textColor="#android:color/black"
android:textStyle="bold"
android:fontFamily="#font/montserrat_regular"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_seat_selected"
android:textStyle="bold"
android:textColor="#android:color/black"
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bt_booking_details"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="17dp"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:fontFamily="#font/montserrat_regular"
android:background="#drawable/circular_button"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Please use the below code snippet for the XML file and change the image view as per your needs.
<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:orientation="vertical"
android:weightSum="12"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="3">
<ImageView
android:id="#+id/wheel"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:src="#drawable/sports" />
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/wheel"
android:layout_marginTop="10dp"
android:numColumns="5"
android:padding="1dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/toys" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Available" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/mobile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Unavailable" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:text="Selected" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:padding="5dp"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:text="Seat Selected : "
android:textColor="#android:color/black"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_seat_selected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:padding="5dp"
android:paddingStart="10dp"
android:paddingLeft="10dp"
android:textColor="#android:color/black"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1">
<Button
android:id="#+id/bt_booking_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:textColor="#android:color/white"
android:textSize="17dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Please try the following code, I just changed the scroll view to be match_parent for width and height and the linear layout to be match_parent for width& wrap_content for height.
Please note that this view won't scroll till you run it on a small screen device.
and please change the images as you need.
<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"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="12">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:weightSum="5"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/wheel"
android:src="#drawable/ic_launcher_background"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="17dp"
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid"
android:layout_marginTop="10dp"
android:layout_below="#+id/wheel"
android:padding="1dp"
android:numColumns="5"
/>
</RelativeLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".4"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:weightSum="3"
android:layout_marginEnd="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:text="Available"
android:paddingStart="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:paddingStart="5dp"
android:text="Unavailable"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight=".5"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1.5"
android:paddingStart="5dp"
android:gravity="center_vertical"
android:text="Selected"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginEnd="10dp"
android:orientation="horizontal"
android:layout_marginStart="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Seat Selected : "
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:textColor="#android:color/black"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_seat_selected"
android:textStyle="bold"
android:textColor="#android:color/black"
android:textSize="18dp"
android:padding="5dp"
android:paddingStart="10dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="0dp"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bt_booking_details"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="17dp"
android:layout_margin="10dp"
android:text="Enter Booking Details"
android:background="#drawable/ic_launcher_background"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

How can I get this interface?

I'm debutant in android and I want to get an interface like this but I couldn't place my linearlayout interface
I tried to use a horizontal and a vertical linearlayout but it doesn't work
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"><TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="#+id/txt1"
android:text="AAAAAAAA"/><Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BE"
android:id="#+id/button1"/></LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="#+id/txt2"
android:text="RRRRRRR"/><LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="#+id/txt3"
android:text="JJJJJJJJJJ"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GO"
android:id="#+id/button2"/>
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="#+id/button3"/>
</LinearLayout>
Can you help me to correct this code?
Try this code.Hope this helps you.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:gravity="center_horizontal">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="AAAAAAAA"
android:textSize="22sp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BE" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
android:text="RRRRRRR"
android:textSize="22sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="JJJJJJJJJJ"
android:textSize="22sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GO" />
</LinearLayout>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_gravity="center_horizontal"
android:text="Start" />
</LinearLayout>
you can try this use RelativeLayout
<?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"
android:orientation="vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:text="AAAAAAAA"
android:textSize="22sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/myl1"
android:gravity="center"
android:text="123465" />
<LinearLayout
android:id="#id/myl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button3"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="123465" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:text="Start" />
</LinearLayout>
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Start" />
</RelativeLayout>

Android: How to draw 8 equal rectangles to fit screen width with XML

I'm new to JAVA and Android development.
Basically I would like to draw 8 equal rectangles (keyboard keys) to fit on 100% width.
As far as I know linearlayout doesn't support drawables, so sadly that piece of code doesn't work for me:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="2">
<View
android:id="#+id/keyboardKey1"
android:background="#drawable/keyboard_key_white"
android:weight="1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_alignTop="#+id/keyboardKeyC"
android:layout_toRightOf="#+id/keyboardKeyA" />
<View
android:id="#+id/keyboardKey2"
android:background="#drawable/keyboard_key_white"
android:weight="1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_alignTop="#+id/keyboardKeyC"
android:layout_toRightOf="#+id/keyboardKeyA" />
</LinearLayout>
Here are the contents of keyboard_key_while.xml as well:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff" />
<stroke
android:width="1dp"
android:color="#000" />
</shape>
As far as I know, I also can't do the the other way round and use linearlayout inside of the drawable XML. Can you give me suggestions of how to achieve that?
Thank you!
I did this before. Let me check my code to see if I still have it.
I found it. The layout I created is for a calculator. I wanted the buttons to scale according to screen size.
I used a TextView with solid white background for the buttons. I'm sure you could use a drawable for a background as well. Anyway, have a look at the way I did the LinearLayouts.
The Code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:background="#ffffffff"
>
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_weight="3"
android:background="#ffffff"
android:text="Food"
android:gravity="center|right"
android:paddingRight="0dp"
android:singleLine="true"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<RelativeLayout
android:id="#+id/more"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/layer_list_arrow_dn"
android:gravity="center"
android:singleLine="true"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:background="#ffffffff"
>
<TextView
android:id="#+id/amount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_weight="3"
android:background="#ffffff"
android:text="0.00"
android:gravity="center|right"
android:paddingRight="0dp"
android:singleLine="true"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<RelativeLayout
android:id="#+id/clear"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/layer_list_clear"
android:gravity="center"
android:singleLine="true"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="#00fcb514"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="0dp"
android:layout_marginRight="5dp"
android:background="#00333333"
>
<TextView
android:id="#+id/b00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#drawable/ripple_holo_blue_bright"
android:text="7"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="4"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="1"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text=""
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#00666666"
>
<TextView
android:id="#+id/b10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="8"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="5"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="2"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text="0"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#00999999"
>
<TextView
android:id="#+id/b20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="9"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="6"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="3"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text="."
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="0dp"
android:background="#00cccccc"
>
<TextView
android:id="#+id/b30"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:textSize="27sp"
android:textStyle="bold"
android:background="#drawable/layer_list_arrow_up"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b31"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/layer_list_arrow_dn"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can do that with a LinearLayout set to horizontal orientation and have each view inside that set an equal layout_weight and zero layout_width. You were almost there but you have to use layout_weight instead of weight.
This shows two keys taking up the width of the screen. If you put 8 views in there it scales accordingly.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:id="#+id/keyboardKey1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#drawable/keyboard_key_white" />
<View
android:id="#+id/keyboardKey2"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#drawable/keyboard_key_white" />
</LinearLayout>
Two more things
in your example you are using RelativeLayout layout parameters in the keyboard views (layout_alignTop and layout_toRightOf). However the keyboard views are being hosted by a LinearLayout and are therefore ignored so they can be left out.
Another way to do this is to use the GridLayout where you can specify how many columns and rows you want. Inside the GridLayout you specify for each child view in which column and row you want it to appear with layout_column and layout_row.
Read up on Layouts on the Android Developer API Guides.

Android Java : Linear Layout vanishes when placed on another Linear Layout

I am working on the horizontal view for a basic Android calculator, and I have a LinearLayout called linearLayout2 that I am trying to place on top of linearLayout3, which contains the numbers 1, 2, 3, +, -, and (. The problem is that when I try to move linearLayout2 on top of linearLayout3, it immedietly vanishes to the top with 0 height.
Here is the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editText"
android:hint="#string/hint"
android:textSize="14dp"
android:background="#00000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:orientation="horizontal"
android:weightSum="1"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="1"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button37"
android:layout_height="wrap_content" />
<Button
android:text="2"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button39"
android:layout_height="wrap_content" />
<Button
android:text="3"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button40"
android:layout_height="wrap_content" />
<Button
android:text="+"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button46"
android:layout_height="wrap_content" />
<Button
android:text="-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button47"
android:layout_height="wrap_content" />
<Button
android:text="("
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button49"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="4"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button41"
android:layout_height="wrap_content" />
<Button
android:text="5"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button42"
android:layout_height="wrap_content" />
<Button
android:text="6"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button43"
android:layout_height="wrap_content" />
<Button
android:text="*"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button35"
android:layout_height="wrap_content" />
<Button
android:text="/"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button36"
android:layout_height="wrap_content" />
<Button
android:text=")"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button38"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout5"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="7"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button44"
android:layout_height="wrap_content" />
<Button
android:text="8"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button45"
android:layout_height="wrap_content" />
<Button
android:text="9"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button48"
android:layout_height="wrap_content" />
<Button
android:text="+/-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button50"
android:layout_height="wrap_content" />
<Button
android:text="%"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button51"
android:layout_height="wrap_content" />
<Button
android:text="^"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button52"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout6"
android:orientation="horizontal"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
>
<Button
android:text="0"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button25"
android:layout_height="wrap_content" />
<Button
android:text="."
android:layout_width="0dp"
android:layout_weight="0.3333"
android:textAllCaps="false"
android:id="#+id/button53"
android:layout_height="wrap_content" />
<Button
android:text="="
android:layout_width="0dp"
android:textAllCaps="false"
android:layout_weight="0.5"
android:id="#+id/button55"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<Button
android:text="Mode"
android:layout_width="0dp"
android:layout_weight="0.50"
android:textAllCaps="false"
android:id="#+id/button3"
android:background="#ffff5830"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Try to use Gridlayout instead of LinearLayout if you want to develop a calculator.
Your Layout2 is using wrap_content for height
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
but there is no content in that group (no child views) so this is correct behaviour as there is no need to make group height bigger.
Also, if you want to stack Layout2 on Layout3 you may consider wrapping themtogether in FrameLayout (or another RelativeLayout)

Categories

Resources