Styling an included layout in Android - android

I have two layouts that contain a functionally identical panel. One requires a background with rounded bottom corners; one requires a background with all square corners. In all other respects, the panels are to be exactly the same.
Is it possible to change the background of the included layout without surrounding it in a <FrameLayout> or other wrapper?

You can create a wrapper layout just for the background and use the include for all the common widgets
first_layout.xml
<?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:background="<FIRST_BACKGROUND>">
<include layout="#layout/main_layout"/>
</LinearLayout>
second_layout.xml
<?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:background="<SECOND_BACKGROUND>">
<include layout="#layout/main_layout"/>
</LinearLayout>
Where main_layout contains all the components that you want to reuse

Related

How to add Buttons and textView inside the fragment of android libraries places widget

I am trying to achieve like the image below how can i do in fragment android.libraries.places.widget i tried using relative layout but its not showing up inside the places widget can anyone suggest some good source to do it or is there any other layout which can be used to do it.
The Xml which i tried:
<?xml version="1.0" encoding="utf-8"?>
<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=".Maps.MapsAddress" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginTop="10dp"
android:id="#+id/autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.libraries.places.
widget.AutocompleteSup portFragment"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chetpet Chennai"
android:textSize="14sp"
android:id="#+id/toolbar_address">
</TextView>
</FrameLayout>
Root layout use : Relative
SearchBar layout can use searchview or floating searchview(external libraries)
Device Location can use relative layout so icon place at the start of parent and etc
Saved addresses you can use table layout.
Assign id to the different layout so that you can stack the layout inside of the root-relative layout

Include layout file into constraint layout without affecting performance or Android Studio previews

I have a huge layout file with one flat constraint layout within.
I have android.support.constraint.Group elements that are identical. I want to move these to a separate file and then include them like <include layout="#layout/selection_group"/>
The problem I'm facing is that the group that I have in the file selection_group.xml is not previewed correctly in Android studio. Is there a way to make Android Studio preview this directly in the file or include them in a different way?
selection_group.xml
<layout 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.support.constraint.Group
android:id="#+id/top_bar_config_one_background_group"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/top_bar_background_with_border_fx"
android:clickable="true"
app:constraint_referenced_ids="top_bar_config_one,top_bar_tooth_one"
app:layout_constraintBottom_toBottomOf="#+id/top_bar_container_background"
app:layout_constraintLeft_toLeftOf="#+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="#+id/top_bar_config_two"
app:layout_constraintTop_toTopOf="#+id/top_bar_container_background" />
<ImageView
android:id="#+id/top_bar_config_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:scaleType="center"
android:src="#drawable/ic_height_over_sea_100x26"
app:layout_constraintBottom_toTopOf="#+id/top_bar_tooth_one"
app:layout_constraintLeft_toLeftOf="#+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="#+id/top_bar_config_two"
app:layout_constraintTop_toTopOf="#+id/top_bar_config_one_background_group" />
<ImageView
android:id="#+id/top_bar_tooth_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/ic_tooth_auto_40x40"
app:layout_constraintBottom_toBottomOf="#+id/top_bar_config_one_background_group"
app:layout_constraintLeft_toLeftOf="#+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="#+id/top_bar_config_two" />
<?xml version="1.0" encoding="utf-8"?>
</layout>
I don't want to nest multiple constraint layouts together. I think the root <layout> view in selection_group.xml is optimized and does not affect the performance? My goal is to reduce redundant code and not affect performance
Try added a merge tag to the included layout:
<layout>
<merge>
<group>
... etc. ...
</merge>
</layout>
In order to make that layout file ready to be included you need to replace <layout> with <merge>
In case you need to use DataBinding into your layout you need to have <layout first and than <merge> tags on top of the layout file
I order to have proper preview in your inner layout which is going to be included - add on top level into merge tag:
tools:parentTag="ContraintLayout"
Something like this:
<merge 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"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">

How can I delete the default Constraint Layout of a blank activity?

When I create a new project in Android studio, and choose a blank activity, there is a default Constraint Layout attached.
I'm trying to follow some online tutorials with a Grid layout, but it's not working as expected because of the constraint layout.
The tutorial is a couple years old so I'm guessing the constraint layout was part of an update.
Is it possible to get rid of this constraint layout?
Below is the default XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.user1.gridlayoutApp.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
</android.support.constraint.ConstraintLayout>
you can just remove ConstraintLayout tags and add LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
Close your IDE and then open again with the help of internet access to update it..

Need pattern background and over it need to place an image

I have a pattern-based background drawable:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/back"
android:tileMode="repeat"/>
On this activity I'm displaying a background-pattern:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
android:scrollbars="vertical"
>
</LinearLayout
Have a result like:
http://img525.imageshack.us/img525/2257/63411225.jpg
Need result:
http://img811.imageshack.us/img811/4894/12572985.jpg
You are not including the necessary code (the layout that has both your background, and the image).
The problem has nothing to do with your background, and (probably) everything to do with how you are actually laying out your image.
If this is you complete code, you need to add a attribute, which would include you Image.

android: add Tab bar to all activities in an application

I have to add TabBar to each activities in my application. How do I do this?
You can use include tag or viewstub or even fragments
Here's how to use include to achieve what you want
Create layout file that describes your toolbar, e.g. toolbar.xml
In each XML layout file you want your toolbar to appear add include tag pointing to your toolbar.xml
Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<include android:id="#+id/titleBar" layout="#layout/title_bar"
android:layout_width="fill_parent" android:layout_height="48dip" />
<!-- All the rest of your activity layout below -->
</RelativeLayout>

Categories

Resources