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.
Related
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
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.
I am Using a imageview under framelayout . I applied a background image in image view but image cannot fully cover the screen. it appears in center. I want to fully cover the Screen ...
How can i achieve it?
Thanx in advance :-)
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="com.example.muhammad.maqalatlayout.jild_copy"
android:background="#color/Green">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/brown_border1"
android:layout_margin="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_gravity="top|left|bottom|center_vertical|right"
android:visibility="visible"
android:adjustViewBounds="false"
android:scaleType="fitStart"/>
My Current output is like this.
I believe your scale isn't working because you are setting the android:background property. Try this:
<ImageView
...
android:src="#mipmap/brown_border1"
... />
Also, preferably put your image in the /drawable/ folder.
use
android:scaleType="fitXY" and `match_parent` instead of `fill_parent`.
I am absolutly a beginner in Android development and I have some problem positioning an image into an ImageView element of my layout. So I have the following situation, I have this fragment layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Dummy content. -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:scaleType="fitCenter"
android:layout_height="350dp"
android:src="#drawable/carbonara"/>
<!--android:background="#drawable/carbonara" />-->
<TextView android:id="#android:id/text1"
style="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
</LinearLayout>
</ScrollView>
So, as you can see in the previous code snippet I am setting a background image into an ImageView having an height of 350dp setted.
The problem is that the image height is less that 350dp and this is what I am obtaining:
As you can see in the previous screenshot what I obtain is that I have the 350dp ImageView (highlighted in blue) and the image is setted inside it vertically centered. I don't want that the setted image is vertically centerd but I want that it start at the top of the ImageView.
How can I implement this behavior? What am I missing?
I have tryed to change:
android:src="#drawable/carbonara"/>
with:
android:background="#drawable/carbonara" />
and in this way it fills all the ImageView space but in this way the image could appear deformed so I think that it is not a good solution.
try to change in your layout and test again.
android:scaleType="fitCenter"
to
android:scaleType="fitStart"
See full docs here
I am making a native android app, I want to draw a vertical line between two columns in a grid-layout, is there any way i can do this ??
In the following screenshot, you can see the lines between cells and between the column. Basically, i just want to display the grid with my own custom style. This is the link to see the screenshots, apparently stack wont let me post a pic
Add verticalSpacing in your grid layout and set GridView background as the color of line you want.
<GridView
android:id="#+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DADADA"
android:verticalSpacing="1dp"
android:numColumns="2" />
You can add a Vertical line like this -
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
You can set the height as per requirement and can add margin to the above View if required
if you use two LinearLayouts side by side you can use the frameworks divider function with an ease:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:divider="?android:listDivider"
android:dividerPadding="2.5dp"
android:orientation="horizontal"
android:showDividers="middle"
android:weightSum="2" > ... </LinearLayout>
See also: http://developer.android.com/reference/android/widget/LinearLayout.html
Maybe something like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:layout_alignParentBottom="true"
android:divider="?android:listDivider"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:showDividers="middle"
android:weightSum="1" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="#dimen/_5sdp"
android:rowCount="2"
android:columnCount="1">
<TextView
android:text="Qty"
/>
<TextView
android:id="#+id/txtQtyProduct"
android:layout_gravity="center"
android:text="1"/>
</GridLayout>
</LinearLayout>