Android layout design - android

I'm sorry if I asking a stupid question here.
I'm looking for android layout design. Is there has a web easy for us to design the android layout and finally generate xml code to android studio.
I wanted to have a layout design as image below, however I don't think it is possible to do using android studio layout.

Try this xml code..
Screenshot
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/value_10"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner_up"
android:padding="#dimen/value_10"
android:text="Choose Station"
android:textColor="#color/black"
android:textSize="#dimen/txt_large" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title1"
android:layout_marginTop="-15dp"
android:background="#drawable/round_corner_up">
<EditText
android:layout_width="350dp"
android:layout_height="70dp"
android:layout_margin="#dimen/value_10"
android:background="#drawable/round_corner_square" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/value_10">
<TextView
android:id="#+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner_up"
android:padding="#dimen/value_10"
android:text="Within Next"
android:textColor="#color/black"
android:textSize="#dimen/txt_large" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title2"
android:layout_marginTop="-15dp"
android:background="#drawable/round_corner_up">
<Spinner
android:layout_width="350dp"
android:layout_height="70dp"></Spinner>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/value_20"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:text="Arrivals"
android:textSize="20sp"
android:drawableLeft="#drawable/drawable1"
android:layout_height="#dimen/value_70" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:text="Departures"
android:textSize="20sp"
android:drawableLeft="#drawable/drawable2"
android:layout_height="#dimen/value_70" />
</LinearLayout>
round_corner_up.xml
<?xml version="1.0" encoding="utf-8"?><!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#7B7D7B" />
<stroke
android:width="3dip"
android:color="#7B7D7B" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
round_corner_square.xml
<?xml version="1.0" encoding="utf-8"?><!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#color/white" />
<stroke
android:width="3dip"
android:color="#color/light_gray" />
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />

You need to divide the layout in smaller elements. e.g. Choose station will be a TextView having a background image and text on it "Choose Station". Below that there will be a Relativelayout with image background and a EditText. There will be a search button with magnifying glass as background drawable. This will be aligned to right of parent so that it be on top of Edittext.

Related

Image View doesn't match parent's rounded cornered background

<FrameLayout
android:id="#+id/flTodayTraining"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/fl_today_training_bg_margin_bottom"
android:layout_marginTop="#dimen/fl_today_training_bg_margin_top"
android:layout_marginHorizontal="#dimen/fl_today_training_bg_margin_horizontal"
android:background="#drawable/today_training_bg"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/tvDaysTrained"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="#dimen/iv_today_training_detail_height"
android:src="#drawable/male_upper_body"
android:scaleType="fitXY"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/upper_body"
android:textSize="#dimen/tv_today_training_detail_text_size"
android:textColor="#color/black"
android:paddingVertical="#dimen/tv_today_training_detail_padding_vertical"
android:gravity="center"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>
That's the cornered background of the frame layout
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/white" />
<corners
android:radius="15dp"
/>
</shape>
As you can see in the image, it's rounded in the bottom, but not in the top, how do I make it rounded in all corners?
Please give me an answer that works on all version, not only api 31 +
Very simple. Just use cardView
see below XML code
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="160dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/fruit1" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg"
android:gravity="center"
android:paddingBottom="5dp"
android:text="Apple"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
and the result is below
pros-
you can easily give elevation to card view to show shadow
easily give it radius.
looks more attractive.
much more.
I hope it'll help you.
Instead of setting the background to the FrameLayout set it to the immediate ViewGroup. Also remove fitXy in the imageview
<FrameLayout
android:id="#+id/flTodayTraining"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/fl_today_training_bg_margin_bottom"
android:layout_marginTop="#dimen/fl_today_training_bg_margin_top"
android:layout_marginHorizontal="#dimen/fl_today_training_bg_margin_horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/tvDaysTrained"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/today_training_bg"<--set it to immediate viewgroup instead
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="#dimen/iv_today_training_detail_height"
android:foreground="#drawable/some_foreground" <-- insert the new background drawable you created
android:scaleType="centerCrop"
android:src="#drawable/male_upper_body" <-- removed fitXy
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/upper_body"
android:textSize="#dimen/tv_today_training_detail_text_size"
android:textColor="#color/black"
android:paddingVertical="#dimen/tv_today_training_detail_padding_vertical"
android:gravity="center"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>
Create this background drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="8dp"
android:color="#color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="#dimen/padding_margin_8" />
<stroke
android:width="8dp"
android:color="#color/white" />
</shape>
</item>
</layer-list>

How do I create an input box using Android's Layout mechanism?

Using Android's Layout mechanism, how do I create an input box with the password icon, and a split between the icon and the input field, as shown below? I'd like to have the border around the input field as well.
you can use imageview and an edit text inside a layout like this
<RelativeLayout
android:layout_width="#dimen/_280sdp"
android:layout_height="#dimen/_30sdp"
android:id="#+id/rl_password"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="#dimen/_15sdp"
android:layout_height="#dimen/_15sdp"
android:src="#drawable/key"
android:layout_centerVertical="true"
android:id="#+id/iv_password"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Password"
android:layout_toRightOf="#+id/iv_password"
android:layout_centerVertical="true"
android:background="#00000000"
android:layout_marginLeft="#dimen/_8sdp"/>
</RelativeLayout>
Try This ....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:layout_margin="40dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:src="#drawable/your_image" />
<View
android:id="#+id/view"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#dbdbdb" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:padding="10dp"
android:inputType="textPassword"
android:background="#android:color/transparent"/>
</LinearLayout>
#drawable/background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#fafafa" />
<corners android:radius="2dp" />
<stroke android:width="1dp" android:color="#dbdbdb" />
</shape>
</item>
</selector>
Sorry, but you will not find a tutorial here.
we guys here don't put tutorial if you have any problem in implementing your code you can ask.
for now, you can watch this tutrial may help.

Custom divider not working in Linear layout

I want to change the color of my Divider for that I am following solution : Change the color of divider in LinearLayout. but my divider not showning
Code :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:divider="#drawable/devider"
android:dividerPadding="12dip"
android:showDividers="middle"
android:layout_gravity="center"
android:gravity="center"
android:background="?android:selectableItemBackground"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textview2"
android:layout_gravity="center"
android:gravity="center"
android:background="?android:selectableItemBackground"
android:text="This is demo of Boderless Button"
android:textColor="#2d2d2d"
android:textSize="20dp"
/>
<ImageButton
style="?android:borderlessButtonStyle"
android:src="#drawable/ic_datarecord"
android:layout_width="wrap_content"
android:id="#+id/imageButton2"
android:layout_height="wrap_content" />
</LinearLayout>
Divide Drawable :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="5dip" />
<solid android:color="#f00" />
</selector>
observed thing : if I use android:divider="?android:dividerVertical" then divider is working
Use this in your drawable xml like following
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="5dip" />
<solid android:color="#f00" />
</shape>

adding custom border drawable to android RelativeLayout not showing - Xamarin Forms

I'm trying to add a background rectangle shape to a custom RelativeLayout in android and I'm following the recommendations of most questions on here by implementing a custom drawable in customborder.xml and setting it as the background of the custom.axml view. I have also tried setting the relativeLayout source as well.
You can see I've also tried it in an imageView which isn't showing up either.
I've messed around with size and color but nothing appears to be rendered.
Am I missing something that needs to be done in code? Or the xml?
customborder.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<corners radius="20dp"/>
<padding left="50dp" right="50dp" top="50dp" bottom="50dp"/>
<stroke width="10dp" color="#B2F7FE"/>
<solid color="white"/>
</shape>
custom.axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="#drawable/customborder">
<ImageView
android:id="#+id/imageViewBackground"
android:layout_width="fill_parent"
android:layout_height="49.0dp"
android:layout_gravity="center"
android:background="#ffededed"
android:adjustViewBounds="false"
android:alpha="1"
android:backgroundTint="#00000000"
android:foreground="#drawable/customborder" />
<refractored.controls.CircleImageView
android:id="#+id/Image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:src="#drawable/icon" />
<LinearLayout
android:id="#+id/Text"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dip"
android:layout_marginLeft="10.5dp"
android:background="#drawable/customborder">
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24dip"
android:textColor="#FFFFFFFF"
android:paddingLeft="5dip"
android:text="Test"
android:layout_marginLeft="46.0dp"
android:layout_marginTop="12.0dp"
android:layout_gravity="left" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="20dip"
android:textStyle="italic" />
</LinearLayout>
Please replace your customborder.xml file with following code,
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
<padding
android:bottom="50dp"
android:left="50dp"
android:right="50dp"
android:top="50dp" />
<stroke android:width="10dp" android:color="#B2F7FE"/>
<solid android:color="#ffffff" />
</shape>
Your mistake was android prefix is missing.Also you are missing close tag in your layout.

Android include shape in xml

Hi have shape and am trying to include this in my layout but it doesn't show?
This is my shape xml "damage.xml"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<solid color="#ff0000" />
<stroke width="3dp" color="#ff0000" />
And this is my I thought I needed to include the Shape in the layout.
<?xml version="1.0" encoding="utf-8"?>
<View android:id="#+id/damage" android:background="#layout/damage"
android:layout_width="5dip" android:layout_height="wrap_content">
</View>
<ImageView android:id="#+id/icon" android:layout_width="60px"
android:layout_height="60px" android:layout_marginRight="6dip"
android:src="#drawable/placeholder" />
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:padding="6dip">
<TextView android:layout_width="fill_parent" android:id="#+id/title"
android:layout_height="wrap_content" android:text="Item Name"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp" />
<ImageView android:id="#+id/rating" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/rating_five" />
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:id="#+id/range"
android:layout_height="wrap_content" android:text="Range"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp"
android:paddingRight="5dip" />
<TextView android:layout_width="fill_parent" android:id="#+id/condition"
android:layout_height="wrap_content" android:text="Condition"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
However nothing is drawn? Where am I going wrong. Secondly is it correct to set the width and heoght of the shape in the View or should I be doing it in the damage.xml? For example
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<solid color="#ff0000" />
<size android:height="wrap_content" />
<size android:width="5dip" />
<stroke width="3dp" color="#ff0000" />
Here the compiler complains about wrap_content.
Any help would be greatly appreciated.
Try changing color="#ff0000" to android:color="#ff0000". That should cause the rectangle to be visible. Once you do that, you will find that a red rectangle shows up, but it fills the parent view vertically. That is because you used android:layout_height="wrap_content", even though the rectangle does not have any fixed height. I would fix that by using some other value for android:layout_height in your layout.
Also, it appears that you have placed damage.xml in the layout directory. Since a shape is a drawable, you should place it in the drawable directory, and reference it as #layout/damage in your layout.
Update:
Using the following code in damage.xml causes the rectangle to show up fine for me.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#f0f000" />
<stroke android:width="3dp" android:color="#ff0000" />
</shape>

Categories

Resources