how to add textview and two buttons below textview in cardview xamarin - button

I have to add tetxview and two buttons inside cardview in such way that,
the two buttons should be on single line and below textview.
also please check below code for reference
here is my code
<FrameLayout xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#333333"
android:text="Caption"
android:id="#+id/textQuestion"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="4dp" />
<Button
android:id="#+id/btnAnswer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Expalantion"
/>
<Button
android:id="#+id/btnVideo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="video"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>

Related

Combining two text views in single line

I want to align text view as mentioned below in my android application
totally two lines
in first line one text view layout weight 2
in second line one text view layout weight 2
the third text view combining both lines and the layout weight 1 and text alignment center
anyone please help me to get fixed this in my android application
the xml layout
<LinearLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/itemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:importantForAutofill="no"
android:padding="15dp"
android:fontFamily="#font/bold"
android:textSize="20sp"
android:textColor="#color/black"
android:textAlignment="center"
tools:ignore="Deprecated,TouchTargetSizeCheck,DuplicateSpeakableTextCheck"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/eancode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:textAlignment="center"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/rate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:importantForAutofill="no"
android:selectAllOnFocus="true"
android:padding="25dp"
android:fontFamily="#font/bold"
android:textSize="40sp"
android:textAlignment="center"
android:textColor="#color/black"
tools:ignore="Deprecated,TouchTargetSizeCheck,SpeakableTextPresentCheck" />
</LinearLayout>
</LinearLayout>
thank you

How to constrain a ScrollView with dynamic contents?

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="25dp">
<TableLayout
android:id="#+id/tableLayoutHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewDeviceName">
</TableLayout>
<ScrollView
android:id="#+id/scrollViewLayoutFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:minWidth="150dp"
android:minHeight="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableLayoutHeader">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/red"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayoutFragments1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/linearLayoutFragments2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
linearLayoutFragments1 and linearLayoutFragments2 have many fragments added at runtime. Unfortunately, scrollViewLayoutFoo is not constrained below tableLayoutHeader, but overflows into tableLayoutHeader.
Could anyone offer a tip on how to fix this?
You were missing some constraints.
You need to constraint the TabLayout to the parent from start/top/end and scroll view constraint to the bottom of it.
There are also referenced some views that are not in the example so you might have to update them accordingly.
<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">
<TableLayout
android:id="#+id/tableLayoutHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_height="48dp" />
<ScrollView
android:id="#+id/scrollViewLayoutFoo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:minHeight="60dp"
android:minWidth="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableLayoutHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayoutFragments1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/linearLayoutFragments2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

Show Notification in full screen

I want create custom ui notification and show it full screen. How can I do it.
<LinearLayout>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/icon_image" />
<TextView
android:id="#+id/alarm_text"
style="#style/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="#string/in_progress" />
<RelativeLayout
android:id="#+id/sticky_header"
android:layout_width="match_parent"
android:layout_height="#dimen/eader_height"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/sticky_text"
style="#style/normal_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/message" />
<TextView
android:id="#+id/button"
style="#style/white"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/msg_selector"
android:gravity="center"
android:text="#string/msg" />
</RelativeLayout>
</LinearLayout>
I know there are RemoteViews we could use, but I am not sure how to set it up to NotificationCompat.Builder
Also I need to take action(launch activity) when the user presses the button in id -> button

Android - Displaying an additional layout underneath an ImageView when using Picasso's fit() and centerInside()

Below is an ImageView that can't 'wrap_content' on the height and width as it is displaying the image using Picasso's fit() and centerInside() attributes.
Due to this, I have to either set a height in dp or state 'match_parent'. If I set a specific height in dp my Button will display but this isn't ideal for different sizes screens of course. If I set 'match_parent' the ImageView fills the rest of the screen and I can't display my Button underneath the ImageView.
Does anyone know of a way to nest my ImageView in some way so I can display my final Button?
Also, I can't work out how to align my picture of the top of the ImageView, please help with this as well if you can.
main_activity.xml.
<?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"
android:background="#color/colorBackground">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:padding="10dp">
<Button
android:id="#+id/button_kitty"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_kitty" />
<Space
android:id="#+id/space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_cat"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_cat" />
</LinearLayout>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/button_layout"
android:layout_marginBottom="17dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="4dp"
android:adjustViewBounds="true" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/button_layout"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:indeterminate="true"
android:visibility="invisible" />
<Button
android:id="#+id/button_facebook"
style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_centerHorizontal="true"
android:gravity="center" />
ActivityMain.java
#Override
public void onResponse(Call<KittyCatModel> call, Response<KittyCatModel> response) {
KittyCatModel model = response.body();
String url = model.getSource();
Picasso.with(this)
.load(url)
.fit()
.centerInside()
.into(imageView, this);
}
On Picasso's github, there's a thread regarding fit() not working when an imageView has adjustViewBounds set to true. Remove either one and see how it goes (I'm doing this from mobile, so can't test it before answering, sorry).
Here's a link to that thread:
https://github.com/square/picasso/issues/425
That thread links to another thread on Picasso's git regarding creating a custom imageView to make this work the way you want
Here's a link to that thread:
https://github.com/square/picasso/issues/457
Had some offline assistance with this issue, answer is:
This is nothing to do with Picasso, it is just an XML issue.
The ImageView and ProgressBar needed to be in a RelativeLayout within a
LinearLayout so I could apply layout_weight=“1” to that RelativeLayout.
This allowed me to “match_parent” on my ImageView width and height so
the image fills its layout but doesn’t hide the bottom button.
Hope that helps somebody else in the future.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_background"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize" />
<LinearLayout
android:id="#+id/button_layout_generate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:orientation="horizontal"
android:padding="12dp">
<Button
android:id="#+id/button_kitty"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_kitty" />
<Space
android:id="#+id/space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_cat"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/button_cat" />
</LinearLayout>
<RelativeLayout
android:id="#+id/image_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/button_layout_generate"
android:layout_weight="1"
android:paddingRight="16dp"
android:paddingLeft="16dp">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
<LinearLayout
android:id="#+id/button_layout_facebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:orientation="horizontal"
android:padding="12dp">
<Space
android:id="#+id/space_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<Button
android:id="#+id/button_facebook"
style="#style/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_weight="1"
android:enabled="false"
android:gravity="center"
android:text="#string/button_facebook" />
<Space
android:id="#+id/space_right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>

adview not showing with bottom on linearlayout

I want to add applications to the ad. But I fail I want to add about the position advertised. Codes are as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="#+id/tarih"
android:textColor="#04B038"
android:textSize="15dp"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/olaylar_liste"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
<ProgressBar
android:layout_gravity="center_vertical|center_horizontal"
android:id="#+id/progress_olaylar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<LinearLayout
android:layout_gravity="bottom"
android:orientation="horizontal"
android:id="#+id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"></LinearLayout>
</LinearLayout>
I want adview showing bottom on linearlayout. Adview # + id /adLayout will be displayed on the Layout
Please help me.
try this
<RelativeLayout 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="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="#+id/tarih"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="Header"
android:textColor="#04B038"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/adLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#ff0000"
android:orientation="horizontal"></LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adLayout"
android:layout_below="#+id/tarih">
<ListView
android:id="#+id/olaylar_liste"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
<ProgressBar
android:id="#+id/progress_olaylar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</FrameLayout>
</RelativeLayout>

Resources