A beehive layout should look like this
The colored hives are just so you understand how I have to lay down elements.
Which Layout widget do you suggest of using?
I tried with GridView but I cannot make such cells, then FrameLayout but don't want to deal with pixel (or dp) values when setting hive location.
I am at my wits end. I am close to conclusion that something like this cannot be done in Android in a high quality way and without using game-like libraries. I hope someone will give me a good clue to solution.
This answer is too late, but someone may find the solution from this, so I am answering this question
I made a simple honeycomb view using ConstraintLayout.
here is the code, You can replace ImageView with any other view
<?xml version="1.0" encoding="utf-8"?>
<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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.MyFragment">
<com.myapp.widget.CustomTextView
android:id="#+id/iv_1"
style="#style/tv_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/honey_comb_center"
android:gravity="center"
android:text="Total\nInvestment"
app:fontName="#string/font_bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/iv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_5sdp"
android:src="#drawable/honey_comb"
app:layout_constraintBottom_toBottomOf="#id/iv_1"
app:layout_constraintRight_toLeftOf="#id/iv_1"
app:layout_constraintTop_toTopOf="#id/iv_1" />
<ImageView
android:id="#+id/iv_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:src="#drawable/honey_comb"
app:layout_constraintBottom_toBottomOf="#id/iv_1"
app:layout_constraintLeft_toRightOf="#id/iv_1"
app:layout_constraintTop_toTopOf="#id/iv_1" />
<ImageView
android:id="#+id/iv_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/honey_comb"
android:translationY="#dimen/_20sdp"
app:layout_constraintBottom_toTopOf="#id/iv_1"
app:layout_constraintLeft_toLeftOf="#id/iv_2"
app:layout_constraintRight_toRightOf="#id/iv_1" />
<ImageView
android:id="#+id/iv_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/honey_comb"
android:translationY="#dimen/_20sdp"
app:layout_constraintBottom_toTopOf="#id/iv_1"
app:layout_constraintLeft_toLeftOf="#id/iv_1"
app:layout_constraintRight_toRightOf="#id/iv_3" />
<ImageView
android:id="#+id/iv_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/honey_comb"
android:translationY="#dimen/_minus20sdp"
app:layout_constraintLeft_toLeftOf="#id/iv_2"
app:layout_constraintRight_toRightOf="#id/iv_1"
app:layout_constraintTop_toBottomOf="#id/iv_1" />
<ImageView
android:id="#+id/iv_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/honey_comb"
android:translationY="#dimen/_minus20sdp"
app:layout_constraintLeft_toLeftOf="#id/iv_1"
app:layout_constraintRight_toRightOf="#id/iv_3"
app:layout_constraintTop_toBottomOf="#id/iv_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
here is the screenshot
Related
I am certainly newbie to Andorid Development, and have a knowledge of basic stuff, Relative Layout, Linear Layout, Intent, File Handling etc....
I need to build a project similar to some E-commerce app.
Here's an image of what I want.
How do I achieve the given view of products, as like in blogs or other websites.
Do I have to use List View?
And Please tell what do I have to use to make that "Add Filter Tags" section and how to achieve what I have shown in the picture.
Below is the code which will create skeleton for your UI requirement. You can modify it according to your need.
Your Activity/Fragment xml will look like :
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/cl_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<com.google.android.material.chip.ChipGroup
android:id="#+id/entry_chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/cl_parent">
</com.google.android.material.chip.ChipGroup>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/entry_chip_group"
/>
</android.support.constraint.ConstraintLayout>
You Adapter xml for RecyclerView will look like:
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_product"
android:layout_width="100dp"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Name"
app:layout_constraintStart_toEndOf="#id/iv_product"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tv_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Information"
app:layout_constraintStart_toStartOf="#id/tv_name"
app:layout_constraintTop_toBottomOf="#id/tv_name" />
<TextView
android:id="#+id/tv_more_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="More info"
app:layout_constraintStart_toStartOf="#id/tv_name"
app:layout_constraintTop_toBottomOf="#id/tv_info" />
<TextView
android:id="#+id/tv_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data"
app:layout_constraintStart_toStartOf="#id/tv_name"
app:layout_constraintTop_toBottomOf="#id/tv_more_info" />
<TextView
android:id="#+id/tv_tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tags"
app:layout_constraintStart_toStartOf="#id/tv_name"
app:layout_constraintTop_toBottomOf="#id/tv_data" />
</android.support.constraint.ConstraintLayout>
You should use Chips for your Filter tag. You can add them dynamically to your chip group. Below is the link for reference.
How to use Android Chips
A ListView would be the "default" way. I would also have a look at RecyclerView (a newer incarnation of the same idea). It handles scrolling and recycling the list elements as you scroll, which are all things you don't really want to do on your own.
You'll probably have a separate layout for the individual cards, probably mostly LinearLayouts (horizontal for image -> content, and then a vertical one to hold the content, and maybe a third horizontal one to list the tags).
For the tags, you might want to take a look at Material Design "chips", but honestly that's the part of this mockup that would have me the most concerned. You can make it look however you want, but I'm not sure what your designer means there exactly. Is that a static list of filtering options? Is that on a new page? In a dialog?
EDIT: And as for the top bar, check out the standard App Bar before reinventing the wheel there.
I would definitely go with Recyclerview or this tutorial for your products(images and the product description...) and FrameLayout for the top that includes logo and stuff and finally a regular RelativeLayout for the tags.
I have two views which have to be placed next to each other horizontally and they need to occupy 50% of the space.
This can be done via guidelines easily.
But the issue is that each of the views has to be able to move to take the space of the other view in case the other view is gone.
This is not possible via guidelines but possible when chains are used.
But the issue with the chain is that i am not able to make sure both (when both are visible) take up 50% of the total width horizontal areas assigned to them.
Could someone please see what the issue is with the code below:
<?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:background="#color/dark_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="15dp"
tools:layout_width="500dp"
tools:layout_height="300dp"
>
<!--<android.support.constraint.Guideline-->
<!--android:id="#+id/guideline"-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="0dp"-->
<!--android:orientation="vertical"-->
<!--app:layout_constraintLeft_toRightOf="#id/title"-->
<!--app:layout_constraintRight_toRightOf="#id/title"-->
<!--app:layout_constraintGuide_percent="0.5"-->
<!--/>-->
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/ic_share"
android:ellipsize="marquee"
android:maxLines="4"
android:textSize="20sp"
android:textColor="#000000"
android:text="This is a test content title. This would be changed eventually"
/>
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:src="#drawable/ic_logo"
app:layout_constraintDimensionRatio="4:3"
app:layout_constraintLeft_toRightOf="#+id/title"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
</android.support.constraint.ConstraintLayout>
Yeah, I think that's a bug. I filed it here:
https://code.google.com/p/android/issues/detail?id=248117
I am trying to place 12 buttons in Grid View. Here is my layout XML file.
How could I use RelativeLayout to achieve this? I am new to Android programming.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/bAries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aries"
android:drawableTop="#drawable/aries" />
<Button
android:id="#+id/bTauras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tauras"
android:drawableTop="#drawable/tauras" />
<Button
android:id="#+id/bGemini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gemini"
android:drawableTop="#drawable/gemini" />
According to your question, I assume following are your requirements, hope they are aligned with what you really need:
12 Buttons to be seen as a Grid
how to use RelativeLayout?
Note:
For a simple thing like this, especially where you know you only need to have a definite number of elements(12 buttons) and that number is static, you don't really need to use a complex layout like GridView, where you must have to implement a ListAdapter to provide the dynamically adding buttons. So the most simplest solution you have is as you have also asked, use a RelaiveLayout as I have provided bellow.
I tried something like following:
<?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="com.androxp.randika.main.MainActivity"
tools:showIn="#layout/activity_main">
<Button
android:id="#+id/bAquarius"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_marginLeft="5dp"
android:text="Aquarius"/>
<Button
android:id="#+id/bPisces"
android:layout_toRightOf="#+id/bAquarius"
android:layout_height="wrap_content"
android:layout_width="115dp"
android:layout_marginLeft="5dp"
android:layout_marginRight=""
android:text="Pisces"/>
<Button
android:id="#+id/bAries"
android:layout_toRightOf="#+id/bPisces"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:layout_marginRight="5dp"
android:text="Aries"/>
<Button
android:id="#+id/bTaurs"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Taurs"
android:layout_below="#+id/bAquarius"
android:layout_alignLeft="#+id/bAquarius"
android:layout_alignStart="#+id/bAquarius" />
<Button
android:id="#+id/bGemini"
android:layout_height="wrap_content"
android:layout_width="115dp"
android:text="Gemini"
android:layout_alignTop="#+id/bTaurs"
android:layout_alignRight="#+id/bPisces"
android:layout_alignEnd="#+id/bPisces" />
<Button
android:id="#+id/bCancer"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Cancer"
android:layout_below="#+id/bAries"
android:layout_alignRight="#+id/bAries"
android:layout_alignEnd="#+id/bAries" />
<Button
android:id="#+id/bLeo"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Leo"
android:layout_below="#+id/bTaurs"
android:layout_alignLeft="#+id/bTaurs"
android:layout_alignStart="#+id/bTaurs"/>
<Button
android:id="#+id/bVirgo"
android:layout_height="wrap_content"
android:layout_width="115dp"
android:text="Virgo"
android:layout_alignTop="#+id/bLeo"
android:layout_alignLeft="#+id/bGemini"
android:layout_alignStart="#+id/bGemini" />
<Button
android:id="#+id/bLibra"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Libra"
android:layout_below="#+id/bCancer"
android:layout_alignRight="#+id/bCancer"
android:layout_alignEnd="#+id/bCancer"/>
<Button
android:id="#+id/bScorpio"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Scorpio"
android:layout_below="#+id/bLeo"
android:layout_alignLeft="#+id/bLeo"
android:layout_alignStart="#+id/bLeo" />
<Button
android:id="#+id/bSagittarius"
android:layout_height="wrap_content"
android:layout_width="115dp"
android:text="Sagittarius"
android:layout_below="#+id/bVirgo"
android:layout_toLeftOf="#+id/bAries"
android:layout_toStartOf="#+id/bAries" />
<Button
android:id="#+id/bCapricorn"
android:layout_height="wrap_content"
android:layout_width="110dp"
android:text="Capricorn"
android:layout_below="#+id/bLibra"
android:layout_alignRight="#+id/bLibra"
android:layout_alignEnd="#+id/bLibra"/>
</RelativeLayout>
Above layout may render out something similar to the following screen:
Clue:
However, I created this using Android Studio. If you are using Eclipse, I recommend you to start using Android Studio as you are just beginning Android App Development.
For Android RelativeLayouts, please read the following References:
Android official documentation for Relative Layout
An excellently matching Tutorial for your requirement
And you may find ton of tutorials for this purpose just by a single search of Google.
Word of Advice:
Whatever you go through to learn Android development, try to use up-to-date materials.
You should use GridView class for this. Here's an official doc and sample
So I'm trying to get used to Android and intending to create an app for the NASA's "Image of the Day" RSS feed, which essentially needs an image- and a couple of text views.
This is my current attempt at the layout (compiling for Android 4.3, if that should matter):
<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"
tools:context="com.headfirst.nasaiodt.Feed" >
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:contentDescription="#string/testImgDescription"
android:src="#drawable/test_img" />
<TextView
android:id="#+id/titleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testTitle" />
<TextView
android:id="#+id/dateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testDate" />
<TextView
android:id="#+id/descriptionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/testContent" />
</LinearLayout>
You'd think that's simple enough for its purposes, however, I just can't seem to get rid of a very resistant white bar on the right side of the picture:
Wasn't
android:layout_width="match_parent"
in the ImageView supposed to take care of that?
(And no, it's not an eclipse glitch, it also shows up in the emulator.)
I'd appreciate your help. What am I doing wrong?
Try using scale type to fit X and Y coordinates. This will solve if its not a glitch.
<ImageView
android:id="#+id/imgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:contentDescription="#string/testImgDescription"
android:src="#drawable/test_img" />
I am a new comer in android. I've tried to make a layout like picture below but I can't make it.
That rectangle is an image and two others are text view. I've tried to make it but it always wrong. Looking forward to hearing from you guys, thanks for advance.
Define one layout as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rlGridRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imageView01"
android:layout_width="36.0dip"
android:layout_height="36.0dip"
android:scaleType="fitCenter"
android:layout_alignParentLeft="true" />
<TextView android:id="#+id/txtLink1"
android:paddingLeft="6.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF00FF"
android:layout_toRightOf="#id/imageView01" />
<TextView android:id="#+id/txtLink2"
android:paddingLeft="6.0dip"
android:paddingBottom="8.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#00FFFF"
android:textSize="12sp"
android:layout_marginTop="-4.0dip" android:layout_toRightOf="#id/imageView01"
android:layout_below="#id/txtLink1" />
</RelativeLayout>
See this link for additional info.