Center textview on RelativeLayout, when other textview it's null (or dont have text)
Tag : java , By : TRobison
Date : March 29 2020, 07:55 AM
To fix this issue I followed this tutorial, for now it's working nice, but i only have a problem, i need to center vertically the "Title" textview, when "Detail" textview text it's null or empty, something like this. I tried this (http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/), and it works, but the problem it's that if i use setVisibility(View.GONE), all the details from all the items, dissapear, and just title get centered., any help appreciated, thanks , Remember to setVisible(View.VISIBLE) when you are recycling a view. String detail = "some detail....";
detailTextView.setVisible(detail == null ? View.GONE : View.VISIBLE);
|
Why dont show button center of screen android?
Date : March 29 2020, 07:55 AM
help you fix your problem I'm beginner in android,and want to write xml file show two button center of screen horizontally,write this code: , Try this code. It will give desired layout <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/TextView01" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/allow"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="@+id/deny"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
|
How to Get location of a button and make Textview appear in the Center of button with Onclick
Date : March 29 2020, 07:55 AM
I hope this helps you . You could simply set a text to the button when it is clicked instead of using a TextView. In your onClick() method write: btnScale.setText("Appear");
android:textColor="@android:color/white"
|
How can I make a wrap_content TextView stay to the left of a Button on ConstraintLayout?
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Your layout is fine, Just set android:layout_width="0dp" to your textView
|
androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.TextView
Date : January 02 2021, 06:48 AM
it helps some times This is because both your ConstraintLayout and TextView is sharing the same id text in your layout XML file. As a result, when you try to refer the TextView in your Java code via R.id.text, it links to your ConstraintLayout instead which causes the crash. Change the id of your ConstraintLayout to something else (like mainlayout). <?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:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:onClick="onButtonClick"
android:text="click me"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text" />
<EditText
android:id="@+id/nameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
|