How to create circle imageview with a transparent border? - java

I want to create an alert dialog same as shown in the image but I am stuck on how to create that center imageview with the transparent border.

Your dialog has some Views which resemble a BottomAppBar and a FloatingActionButton. Of course it is possible to write a custom View which looks just like a BottomAppBar, but it's easier to use the original thing.
You can use the following layout for the dialog (I left out the button bar because I think you already know you can achieve this with e.g. a LinearLayout):
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_gravity="bottom"
app:backgroundTint="#0000ff"
app:fabAlignmentMode="center"
app:fabCradleMargin="4dp"
app:fabCradleRoundedCornerRadius="0dp"
app:fabCradleVerticalOffset="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp"
android:text="#string/lorem_string"
android:lines="3"
android:ellipsize="end"
android:padding="16dp"
android:layout_gravity="bottom"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bar"
app:elevation="0dp"/>
For more information on styling the BottomAppBar, see the developer documentation

Related

How to curve a small part in a circular cardview in android to show the online status icon occupy at the bottom

I have used circular cardview to show the user status as online. But the circular has a small curve to occupy the status enable icon.
How can I acheive this in android. My code shows the circular image.
<androidx.cardview.widget.CardView
android:id="#+id/myCardView"
android:layout_width="70dp"
android:layout_height="70dp"
app:cardCornerRadius="50dp"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
>
</androidx.cardview.widget.CardView>
<ImageView
android:id="#+id/user_online_status"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="0dp"
android:visibility="visible"
android:src="#drawable/circle_green_posts"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|start"
android:layout_marginTop="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="Username">
</TextView>
If I understood you question correctly, all you need to do is to put this inside some kind of parent layout (Relative, Constraint). Then simply put this circular shape to the bottom right, and above the card view.

ConstraintLayout applying margin bottom to a view, also applies it to the top of the view

I have a TextView, below it an EditText and below it another TextView. When I apply a bottom margin of 12 dp to the EditText, it's applied but it also applies to the top of the view. I don't know if this is the way ConstraintLayout works. marginTop works as expected.
https://i.stack.imgur.com/VEOUz.jpg
From what i can see in your attachment you are creating a vertical chain but you didn't restrain your "description" to the bottom. This could cause issues since the constraint layout doesn't know where the chain ends. make sure you add app:layout_constraintBottom_toBottomOf="parent" or whatever view you need as a bottom chain constraint on the description TextView.
I recreated your example and there is mirror margin for the edit text.
<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">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
app:layout_constraintBottom_toTopOf="#id/editText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" />
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="edit text"
app:layout_constraintBottom_toTopOf="#+id/description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/name" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description"
android:textColor="#color/colorTextPrimaryLight"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText" />
You can play around with the chainStyle to see which fits best your needs.

ConstrainLayout not respecting the hierarchy

I have this layout
....................
<CheckBox
android:id="#+id/cb_remember_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textinput2"
android:text="#string/keep_login"
android:textColor="#android:color/holo_red_dark"
android:textSize="18sp"
android:layout_marginTop="14dp"
app:layout_constraintTop_toBottomOf="#+id/textinput2"
app:layout_constraintBottom_toTopOf="#+id/btn_signin_login" />
<Button
android:id="#+id/btn_signin_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/cb_remember_login"
android:backgroundTint="#color/colorAccent"
android:minHeight="75dp"
android:text="#string/signin"
android:textColor="#android:color/background_light"
android:textSize="30sp" android:visibility="visible"
android:layout_marginTop="36dp"
app:layout_constraintTop_toBottomOf="#+id/cb_remember_login"
app:layout_constraintBottom_toTopOf="#+id/tv_forgot_login"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<include
layout="#layout/view_circle_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#+id/btn_signin_login"
app:layout_constraintBottom_toBottomOf="btn_signin_login"
app:layout_constraintLeft_toLeftOf="#+id/btn_signin_login"
app:layout_constraintRight_toRightOf="#+id/btn_signin_login" />
<TextView
android:id="#+id/tv_forgot_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_signin_login"
android:text="#string/forgot_pass"
android:textAlignment="center"
android:textColor="#android:color/holo_red_dark"
android:textSize="18sp"
android:layout_marginTop="14dp"
app:layout_constraintTop_toBottomOf="#+id/btn_signin_login"
app:layout_constraintBottom_toTopOf="#+id/tv_copyrights_login"
tools:layout_editor_absoluteX="0dp" />
...........][1]][1]
Here is view_circle_progress.xml
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:indeterminateTint="#color/red">
</ProgressBar>
You can see my included layout comes after the button but in the picture you can see it's actually beneath the button. Please help with a solution. Also except the included layout all the views are in a chain.
Go to your xml, click design. The on the upper left, corner you will see an icon similar to a blueprint. Click on it and you will get your layout as a blue print. Then click on the element that you want, you will see four points on all sides. Click on the upper point and drag it to the upper bar(menu, etc.). That way you will attach it and it will stay in place. If you want to make offset look on you right above the properties you will see a box representing the item with its constraints, just put the distance you want, and you will have your offset.
The problem was in Android 5.0 elevation is introduced. A button has a default elevation that's why it was always showing on top. Setting elevation value to my include layout solve the problem.

Drawing line between two drawables in the textviews

I have the issue with drawing line like in a pic above. How can I do that? Here's the code of the view, where I need to implement that. I guess I need to use canvas, but I'm not sure about that. Thanks for any advice!
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/linear_layout_buttons_margin_top"
android:orientation="vertical">
<TextView
android:id="#+id/button_from_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_marginTop="4dp"
android:background="#drawable/button_white"
android:drawableLeft="#drawable/ic_green"
android:drawablePadding="#dimen/dots_white_button_padding"
android:drawableStart="#drawable/ic_green"
android:gravity="center_vertical"
android:hint="#string/from_place"
android:padding="#dimen/dots_white_button_padding"
android:textColor="#color/color_accent"
android:textColorHint="#color/text_view_hint_color"/>
<TextView
android:id="#+id/button_to_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/button_from_city"
android:layout_marginBottom="4dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_marginTop="4dp"
android:background="#drawable/button_white"
android:drawableLeft="#drawable/ic_red"
android:drawablePadding="#dimen/dots_white_button_padding"
android:drawableStart="#drawable/ic_red"
android:gravity="center_vertical"
android:hint="#string/to_place"
android:padding="#dimen/dots_white_button_padding"
android:textColor="#color/color_accent"
android:textColorHint="#color/text_view_hint_color"/>
</RelativeLayout>
You can provide two drawable resources for the textviews and set them as drawableStart, based on the required conditions of your work. The point here is using an image which contains a colored circle and a line, which is much simpler than drawing the layout with canvas.
I will simply add two View with grey background of 1dp width above and below your dot drawable and manage visibility depending on the position of your items.

GridView not conforming to Relativelayout alignment

I'd like to right align this gridview so that it's flush against the right side of the screen, but it seems to always immediately follow whichever textview I set it to the right of. Not only that, but all of the textviews are displayed on top of each other.
<?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">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/time_left"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:id="#+id/time_left_label"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/time_left"
android:layout_alignParentLeft="true"
android:layout_below="#id/time_left_label"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/progress"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_below="#id/time_left"
android:id="#+id/progress_label" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/progress"
android:layout_alignParentLeft="true"
android:layout_below="#id/progress_label"/>
<GridView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/main_grid"
android:numColumns="2"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/time_left_label"
android:stretchMode="none" />
</RelativeLayout>
Here's a picture of what I want drawn quickly in paint!
http://imgur.com/x7Ypr
I'd like to right align this gridview
How exactly do you want it aligned? You mention what it does, but not what you want.
it seems to...follow whichever textview I set it to the right of
Welll, you're using layout_alignParentRight and layout_toRightOf.
the textviews are displayed on top of each other.
Placing your TextViews underneath each other won't stack them. You can use a LinearLayout with its orientation set to vertical or you could use layout_below to place them under each other.

Categories