I have given a fixed android:layout_width="300dp"
, but despite that, the width changes depending on the content of the TextView
. Why? How can I keep the width fixed? Instead, the height can changes.
<?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:layout_width="300dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="tips"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/store"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:text="store"
android:textAlignment="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tips" />
<Button
android:id="@+id/get"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="GET"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/store" />
<Button
android:id="@+id/go"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:text="GO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/store" />
</androidx.constraintlayout.widget.ConstraintLayout>
EDIT
MapsActivity.java
db.collection("Stores").addSnapshotListener((queryDocumentSnapshots, e) -> {
if (queryDocumentSnapshots != null) {
for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
try{
MarkerOptions options = new MarkerOptions()
.position(new LatLng(document.getGeoPoint("geoPoint").getLatitude(), document.getGeoPoint("geoPoint").getLongitude()))
.title(String.valueOf(document.get("name")))
.snippet(String.valueOf(document.get("balanceTips")))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
CustomInfoWindowGoogleMap customInfoWindow = new CustomInfoWindowGoogleMap(this);
mMap.setInfoWindowAdapter(customInfoWindow);
mMarker = mMap.addMarker(options);
Log.d(TAG, "addStoresOnMap: " + document.get("name") + " added");
}catch (NullPointerException eTry){
Log.e(TAG, "addStoresOnMap: NullPointerException: " + eTry.getMessage() );
}
}
}
});
CustomInfoWindowGoogleMap.java
public class CustomInfoWindowGoogleMap implements GoogleMap.InfoWindowAdapter {
private Context context;
public CustomInfoWindowGoogleMap(Context ctx){
context = ctx;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = ((Activity)context).getLayoutInflater()
.inflate(R.layout.maps_details, null);
TextView name = view.findViewById(R.id.store);
TextView balanceTips = view.findViewById(R.id.tips);
name.setText(marker.getTitle());
balanceTips.setText(marker.getSnippet());
return view;
}
}