I need to do some User Interface design in android application,most probably for a front page only.
For an example: I need to do like this below image.
I tried like placing an image in layout and coloring the action, but I didn't get the perfect effect.If I get some samples or Github post or some other suggestion that will be helpful to me.
You can try this library https://github.com/kmshack/Android-ParallaxHeaderViewPager
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fr.castorflex.android.googleplusprofilepageapp.ParallaxImageView ... />
<LinearLayout ... >
<TextView ... />
<TextView ... />
<TextView ... />
</LinearLayout>
<!-- we add one more container to facilitate the add/remove view -->
<FrameLayout android:id="#+id/tabs_container"
android:layout_height="48dp"
android:layout_width="match_parent"
android:layout_below="#+id/informations_container">
<HorizontalScrollView
android:id="#+id/horizontalscrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- tabs here -->
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
<ImageView ... />
</RelativeLayout>
Check this for more info
Related
How to include layout inside layout in Android?
I am creating common layout. I want to include that layout in another page.
Edit: As in a comment rightly requested here some more information. Use the include tag
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/yourlayout" />
to include the layout you want to reuse.
Check this link out...
Note that if you include android:id... into the <include /> tag, it will override whatever id was defined inside the included layout. For example:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_id_if_needed"
layout="#layout/yourlayout" />
yourlayout.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_other_id">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
</LinearLayout>
Then you would reference this included layout in code as follows:
View includedLayout = findViewById(R.id.some_id_if_needed);
Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);
Use <include /> tag.
<include
android:id="#+id/some_id_if_needed"
layout="#layout/some_layout"/>
Also, read Creating Reusable UI Components and Merging Layouts articles.
Try this
<include
android:id="#+id/OnlineOffline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="#layout/YourLayoutName" />
From Official documents about Re-using Layouts
Although Android offers a variety of widgets to provide small and
re-usable interactive elements, you might also need to re-use larger
components that require a special layout. To efficiently re-use
complete layouts, you can use the tag to embed another
layout inside the current layout.
Here is my header.xml file which i can reuse using include tag
<?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="fill_parent"
android:background="#FFFFFF"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#000000" />
</RelativeLayout>
No I use the tag in XML to add another layout from another XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f0f0f0" >
<include
android:id="#+id/header_VIEW"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/header" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
Learn More Using this link
https://developer.android.com/training/improving-layouts/reusing-layouts.html
<androidx.constraintlayout.widget.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=".Game_logic">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="#+id/text1"
android:textStyle="bold"
tools:text="Player " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:id="#+id/text2"
tools:text="Player 2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Blockquote
Above layout you can used in other activity using
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.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=".SinglePlayer">
<include layout="#layout/activity_game_logic"/>
</androidx.constraintlayout.widget.ConstraintLayout>
i need to add header image like this Post :
can I add an image header in navigation drawer layout
but, im using android studio sample navigation drawer for doing this.
it is good or bad for design this ?
and the better way or Compact way for doing this ?
any suggestion ?
thanks.
Can I add an Image Header in Navigation Drawer Layout?
Yes you can add with no problems.
If you use android studio navigation drawer or some thing else every thing are same. Some additional methods will be present and you need to check the methods required by you and delete other methods. You may also need to add few methods.
As per the latest android, best way of designing navigation drawer is by using recycler view and by using material design.
There are lot of materials in google for doing this, one of the finest tutorials I prefer is in the link given below you can have a look:
https://www.youtube.com/watch?v=zWpEh9k8i7Q&list=PLonJJ3BVjZW6CtAMbJz1XD8ELUs1KXaTD&index=6
Hope it helps.
In the menudrawer activity setcontentview(layout).Inside this layout
try to add an imageview.My sample xml is as folllows
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<LinearLayout
android:layout_height="match_parent"
android:layout_width="120dp"
android:weightSum="7"
android:layout_gravity="start"
android:id="#+id/parentlayoutt"
android:choiceMode="singleChoice"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:id="#+id/headerimage"
android:src="#drawable/yourimage"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/parentmenuone"
android:soundEffectsEnabled="true"
android:descendantFocusability="blocksDescendants"
android:background="#color/pure_white"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/birdwhite"
android:background="#color/white"
android:id="#+id/sidejive1"
android:clickable="false"
android:layout_centerInParent="true"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/sidejive1"
android:id="#+id/title1"
android:clickable="false"
android:textColor="#color/violetbg"
android:text="#string/createmenu"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:descendantFocusability="blocksDescendants"
android:id="#+id/parentmenutwo"
android:background="#drawable/whitebox"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/profilewhite"
android:background="#color/white"
android:id="#+id/sidejive2"
android:clickable="false"
android:layout_centerInParent="true"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/sidejive2"
android:id="#+id/title2"
android:clickable="false"
android:textColor="#color/violetbg"
android:text="#string/Accountmenu"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:descendantFocusability="blocksDescendants"
android:id="#+id/parentmenuthree"
android:background="#drawable/whitebox"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/homewhite"
android:background="#color/white"
android:id="#+id/sidejive3"
android:clickable="false"
android:layout_centerInParent="true"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/sidejive3"
android:id="#+id/title3"
android:textColor="#color/violetbg"
android:text="#string/Dashboardmenu"
android:clickable="false"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/parentmenufour"
android:descendantFocusability="blocksDescendants"
android:background="#drawable/whitebox"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/examplewhite"
android:background="#color/white"
android:id="#+id/sidejive4"
android:clickable="false"
android:layout_centerInParent="true"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/sidejive4"
android:id="#+id/title4"
android:textColor="#color/violetbg"
android:text="#string/Examplemenu"
android:clickable="false"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
I am developing an application and I need an explanation on how can I realize a listview made of custom items like this:
How can I organize things like that? And what should I use?
(Sorry for the poor quality of the image)
A basic design for ListView item could be something like this
<ListView>
<!-- container for the basic design -->
<LinearLayout
android:orientation="horizontal">
<!-- Left side column -->
<LinearLayout
android:orientation="vertical">
<ImageView />
<TextView />
</LinearLayout>
<!-- Right side column -->
<LinearLayout
android:orientation="vertical">
<TextView />
<!-- add Text and 3 images in this LinearLayout -->
<LinearLayout
android:orientation="horizontal" />
<TextView />
</LinearLayout>
</LinearLayout>
</ListView>
Then add your own custom adaptor to add the item in the ListView. Here is a good tutorial answer on SO: https://stackoverflow.com/a/6860788/2777098
You can use LinearLayout weigth.But its not recommended for performance.There are other ways.Like grid .
Your Custom list item shoul be like this.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.7"
android:background="#color/Black">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1.3"
android:weightSum="2"
android:background="#color/Red">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.6">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.4"
android:background="#color/Aqua">
</LinearLayout>
</LinearLayout>
My application have a viewpager with the following fragment
1 Login 2 Measure 3 View Data
After the user login and swipe to the measure fragment my app will automatically measure some parameters.
As the viewpager is swipe-able . Is is possible to greyout/disable a fragment in the case where the user want to measure without login.
Thanks.
<?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" >
<ImageButton
android:id="#+id/qt_deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/qt_testtype"
android:layout_marginLeft="28dp"
android:layout_marginTop="18dp"
android:layout_toRightOf="#+id/qt_saveButton"
android:background="#drawable/border_button"
android:src="#drawable/delete" />
<ImageButton
android:id="#+id/qt_saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/qt_deleteButton"
android:layout_toRightOf="#+id/maintxt_measure"
android:background="#drawable/border_button"
android:src="#drawable/save" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/main_unknown" />
</FrameLayout>
</RelativeLayout>
I have edit my layout file to the above however the layer below is still clickable. Is there any thing i missed ?
Thanks
Sorry but no, this is how it should probably look like:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- You may change this to your relative layout, just make sure it is fill_parent -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<!-- Everything related to your main activity goes here -->
</LinearLayout>
<LinearLayout
android:id="#+id/faderLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E0000000"
android:onClick="faderClicked" />
</LinearLayout>
</FrameLayout>
So, in your activity, you will have a function public void faderClicked(View v) where it does nothing at all, and you control the view by changing faderLayout's visibility.
How to include layout inside layout in Android?
I am creating common layout. I want to include that layout in another page.
Edit: As in a comment rightly requested here some more information. Use the include tag
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/yourlayout" />
to include the layout you want to reuse.
Check this link out...
Note that if you include android:id... into the <include /> tag, it will override whatever id was defined inside the included layout. For example:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_id_if_needed"
layout="#layout/yourlayout" />
yourlayout.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_other_id">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
</LinearLayout>
Then you would reference this included layout in code as follows:
View includedLayout = findViewById(R.id.some_id_if_needed);
Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);
Use <include /> tag.
<include
android:id="#+id/some_id_if_needed"
layout="#layout/some_layout"/>
Also, read Creating Reusable UI Components and Merging Layouts articles.
Try this
<include
android:id="#+id/OnlineOffline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="#layout/YourLayoutName" />
From Official documents about Re-using Layouts
Although Android offers a variety of widgets to provide small and
re-usable interactive elements, you might also need to re-use larger
components that require a special layout. To efficiently re-use
complete layouts, you can use the tag to embed another
layout inside the current layout.
Here is my header.xml file which i can reuse using include tag
<?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="fill_parent"
android:background="#FFFFFF"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#000000" />
</RelativeLayout>
No I use the tag in XML to add another layout from another XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f0f0f0" >
<include
android:id="#+id/header_VIEW"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/header" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
Learn More Using this link
https://developer.android.com/training/improving-layouts/reusing-layouts.html
<androidx.constraintlayout.widget.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=".Game_logic">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="#+id/text1"
android:textStyle="bold"
tools:text="Player " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:id="#+id/text2"
tools:text="Player 2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Blockquote
Above layout you can used in other activity using
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.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=".SinglePlayer">
<include layout="#layout/activity_game_logic"/>
</androidx.constraintlayout.widget.ConstraintLayout>