Java android frame layout - java

I want to do this :
I did this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_aplication_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e2e2e2"
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.smok.maps.AplicationSettings">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/textSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="#string/sync" />
<LinearLayout
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textSync">
<TextView
android:id="#+id/actual"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="#string/actual" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/count" />
<TextView
android:id="#+id/actual2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="min" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/line1"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="50dp"
android:layout_height="50dp"
android:button="#xml/setting_checkbox"
android:focusable="false"
android:gravity="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/point" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#000000"
android:text="#string/show_choose_point" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lin2"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="50dp"
android:layout_height="50dp"
android:button="#xml/setting_checkbox"
android:focusable="false"
android:gravity="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/sync" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#000000"
android:gravity="center"
android:text="#string/sync_request" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lin3"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="50dp"
android:layout_height="50dp"
android:button="#xml/setting_checkbox"
android:focusable="false"
android:gravity="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/show_chooce" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#000000"
android:gravity="center"
android:text="#string/show_choosen_points" />
</LinearLayout>
<LinearLayout
android:id="#+id/lin5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lin4"
android:orientation="horizontal">
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="50dp"
android:layout_height="50dp"
android:button="#xml/setting_checkbox"
android:focusable="false"
android:gravity="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/position2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#000000"
android:text="#string/current_location" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal">
<Button
android:id="#+id/back_bt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#ffffff"
android:background="#xml/roundedbutton"
android:text="#string/back" />
<View
android:layout_width="0dp"
android:layout_weight="0.1"
android:layout_height="match_parent">
</View>
<Button
android:id="#+id/confirm_bt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#ffffff"
android:background="#xml/roundedbutton"
android:text="#string/save" />
</LinearLayout>
</RelativeLayout>
I don't have idea how I can do border. I want to do a border and in the middle I want to have place to put text.This same how is in the screen. This look like a frame which have a text. Now I have onli text and I don not how I can create a frame.

Here is demo of your requirement.
1) You need to create a border.xml. Put this in your drawable folder. Add the following code in border.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--stroke width and color-->
<stroke
android:width="2dp"
android:color="#android:color/darker_gray" />
<!-- corner radius-->
<corners
android:radius="5dp" />
<!--paddings-->
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
2) Here is the layout.xml put the background to a linearlayout accordingly:
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="bd.com.tahsin.myapplicationnavgroup.MainActivity"
tools:showIn="#layout/app_bar_main">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_marginTop="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:background="#drawable/bottom_border_help">
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MENU_BOCZNE"
android:background="#color/background_floating_material_light"
android:layout_marginLeft="10dp" />
</RelativeLayout>
3) And finally the screen-shot:
Hope, this will help a bit.

Try this,
<?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:layout_margin="15dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="TEST"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text=" MENU "
android:layout_marginLeft="15dp"
android:background="#ffffff"
android:textSize="17sp" />
</RelativeLayout>
xml of border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="3dp"/>
<stroke
android:width="2dp"
android:color="#cdcdcd" />
</shape>

Related

Layout below not working in android relative xml

I'm confused why android:layout_below is not working, I just need to put the button below the border line and I don't wanna use android:layout_marginTop="570dp because the android phone has different sizes, Is somebody know how can I arrange the layout of this? it helps me a lot thanks in advance.
This is what I want to achieve
<?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:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="100dp"
android:background="#drawable/selector_fieldset_background"
android:orientation="vertical"
android:id="#+id/linearl">
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#color/white"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Cash Card Scanner"
android:textSize="15dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<Button
android:id="#+id/button2"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCAN"
android:layout_below="#+id/linearl"
/>
</RelativeLayout>
Drawable selector_fieldset_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<stroke
android:width="2dip"
android:color="#25000000" />
</shape>
Just try this, works for me:
<?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:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/selector_fieldset_background"
android:orientation="vertical"
android:id="#+id/linearl"
android:layout_above="#+id/button2"
>
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#color/white"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Cash Card Scanner"
android:textSize="15dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<Button
android:id="#+id/button2"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="90dp"
android:text="SCAN"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

Alert dialog box Shifting left and right

Well I have achieved the rounded corner goal in alert dialog box but it has taken all the left and right side.
My question is like I want some space between left and right of the dialog box
Here is my code:Custom dialog
<?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="wrap_content"
android:orientation="vertical"
android:background="#drawable/custom_dialog"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="SELECT PHOTO"
android:textSize="15dp"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:layout_marginLeft="20dp"></TextView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/hint_color"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="15dp"
android:id="#+id/Select_photo_from_Camera">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/camera_24dp"
android:layout_marginLeft="22dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera"
android:layout_marginLeft="10dp"
></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="600dp"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/hint_color"></View>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="15dp"
android:paddingBottom="5dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_photo_library_black_24dp"
android:layout_marginLeft="22dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gallery"
android:layout_marginLeft="10dp"
/>
</LinearLayout>
</LinearLayout>
Code for :Custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#color/white"></solid>
<corners
android:radius="5dp"
></corners>
<padding
android:top="6dp"
android:bottom="6dp"></padding>
</shape>
Here is the Output of my achievement:
https://i.stack.imgur.com/7G0Go.png
Create a inset and set as background, that may help
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/your_background_image"
android:insetRight="25dip"
android:insetLeft="25dip" />
use
android:background="#drawable/inset_background"

Add shadow between layout

I'm trying to do this for months and finally i can't find anyway. Elevation is just for API 21+ and other ways sometimes work and sometimes doesn't. I'm working on a music player and i need shadow between music controller and musics cover. How to add shadow? elevation doesn't work here as you can see
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ImageView
android:id="#+id/now.playing.cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:scaleType="centerInside"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="#+id/now.title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/colorSecondaryText" />
<TextView
android:id="#+id/now.artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/colorSecondaryText" />
<TextView
android:id="#+id/now.album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/colorSecondaryText" />
<android.support.v7.widget.AppCompatSeekBar
android:id="#+id/now.seek"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:layout_marginTop="8dp"
android:paddingRight="32dp">
<ImageView
android:id="#+id/prev"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginRight="56dp"
android:padding="2dp"
android:src="#drawable/prev" />
<ImageView
android:id="#+id/pp"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginRight="56dp"
android:padding="2dp"
android:src="#drawable/play" />
<ImageView
android:id="#+id/next"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="2dp"
android:src="#drawable/next" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can add a view in between which looks like shadow..
Below is an example of same which I have used and it almost works on all the apis.. May be it can help you..
Shadow View:
<View
android:id="#+id/toolbar_shadow"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_below="#+id/toolbar"
android:background="#drawable/toolbar_shadow" />
And the drawable file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#88444444"
android:startColor="#00000000" />
</shape>

Adding a normal Layout under a MapFragment

i'm trying to add a menu panel under a MapFragment but the thing always appear in the middle of the screen, like floating. I've tried several layout configurations but nothings seems to work.
This is my layout:
<FrameLayout 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=".MapActivity" >
<fragment
android:id="#+id/panel_map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/newmarker"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_gravity="center"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Nuevo marcadort"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/newmarker_options"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/newmarker_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="#+id/newmarker_delete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
This is the actual result:
Any idea? What I'm doing wrong?
i just added android:layout_gravity="bottom" to newmarker layout
<FrameLayout 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=".MapActivity" >
<fragment
android:id="#+id/panel_map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<LinearLayout
android:layout_gravity="bottom"
android:id="#+id/newmarker"
android:layout_width="match_parent"
android:layout_height="85dp"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Nuevo marcadort"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/newmarker_options"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/newmarker_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="#+id/newmarker_delete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</FrameLayout>

2 TextView multilines in android

I want to make quiz app. I have two Textview and one edit text.
I placed the edittext between two textview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/first_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:textSize="18sp" />
<EditText
android:id="#+id/first_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/second_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:lines="6"
android:textSize="20sp" />
</LinearLayout>
<Button
android:id="#+id/btnCheckAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check" />
</LinearLayout>
how to make text from the second textview below first textview?
I want to make the words "Nijuu sai desu. Chugoku desu." below "Watashi wa".
try
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/first_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:textSize="18sp" />
<TextView
android:id="#+id/second_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="6"
android:singleLine="false"
android:textSize="20sp" />
</LinearLayout>
<EditText
android:id="#+id/first_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
you can try
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/first_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:textSize="18sp" />
<EditText
android:id="#+id/first_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/second_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:lines="6"
android:textSize="20sp" />
</LinearLayout>
<Button
android:id="#+id/btnCheckAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check" />
</LinearLayout>

Categories

Resources