I have a mapview on a fragment of my activity with a constraint layout. I need it to fit the rest of the space that is in the fragment, so I use "0dp" height.
The problem is that it does not show, but if I give it a fixed height like "150dp", it shows correct.
What can be the problem? Thanks
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_inicio, container, false);
// Asignacion layout.
asignaComponentes(view);
asignaTipoLetra();
fragmentoPadre = container;
inicializaCups();
actualizaTablaUltimosConsumos();
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
actualizaMapa();
return view;
}
#Override
public void onMapReady(GoogleMap gmap) {
map = gmap;
setUpMap(null);
}
public void setUpMap(Cups cupsMapa){
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
#Override
public void onResume() {
mapView.onResume();
super.onResume();
}
#Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
And this is XML with Constraint layout
Capture of XML
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/colorGrisClaroViesgo"
tools:context="viesgo.cic.es.appconsumidores.inicio.Inicio">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout14"
style="#style/TextoBlanco3D"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent">
<ImageView
android:id="#+id/inicioImagenBombilla"
style="#style/BotonTransparenteRojo"
android:layout_width="35dp"
android:layout_height="35dp"
app:srcCompat="#mipmap/bulb"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:id="#+id/inicioTextoDireccion"
style="#style/LabelRojo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Direccion"
app:layout_constraintRight_toLeftOf="#+id/inicioBotonAtras"
android:layout_marginRight="4dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
app:layout_constraintLeft_toRightOf="#+id/inicioImagenBombilla"
android:layout_marginLeft="0dp" />
<ImageButton
android:id="#+id/inicioBotonAtras"
style="#style/BotonTransparenteRojo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/refresh"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="0dp" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout16"
style="#style/TextoBlanco3D"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/inicioBotonContrato"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout14">
<ImageView
android:id="#+id/imageView29"
android:layout_width="10dp"
android:layout_height="9dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toTopOf="#+id/inicioLabelReportada"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/inicioLabelDetectada"
app:srcCompat="#mipmap/icosinsuministro" />
<TextView
android:id="#+id/inicioLabelDetectada"
style="#style/LabelNegro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:text="Incidencia detectada en la red"
android:textSize="12dp"
app:layout_constraintLeft_toRightOf="#+id/imageView29"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
<ImageView
android:id="#+id/imageView30"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toTopOf="#+id/inicioLabelSinIncidencia"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/inicioLabelReportada"
app:layout_constraintVertical_bias="0.5"
app:srcCompat="#mipmap/icoaviso" />
<TextView
android:id="#+id/inicioLabelReportada"
style="#style/LabelNegro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:text="Incidencia reportada"
android:textSize="12dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="#+id/imageView30"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inicioLabelDetectada" />
<ImageView
android:id="#+id/imageView31"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
app:layout_constraintBottom_toBottomOf="#+id/inicioLabelSinIncidencia"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/inicioLabelSinIncidencia"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="#mipmap/icosinproblemas" />
<TextView
android:id="#+id/inicioLabelSinIncidencia"
style="#style/LabelNegro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:text="Sin incidencia detectada o reportada"
android:textSize="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="#+id/imageView31"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inicioLabelReportada"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/inicioBotonContrato"
style="#style/TextoBlanco3D"
android:textColor="#color/colorRojoViesgo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginRight="16dp"
android:layout_marginTop="0dp"
android:text="Ver contrato"
android:drawableTop="#mipmap/edit"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/constraintLayout16"
app:layout_constraintBottom_toBottomOf="#+id/constraintLayout16"
android:layout_marginBottom="0dp">
</Button>
<com.google.android.gms.maps.MapView
android:id="#+id/inicioMapa"
style="#style/TextoBlanco3D"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
app:layout_constraintBottom_toTopOf="#+id/inicioLabelConsumos"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout16" />
<TextView
android:id="#+id/inicioLabelConsumos"
style="#style/LabelTituloRojo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Últimos consumos"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/inicioRecyclerConsumos" />
<android.support.v7.widget.RecyclerView
android:id="#+id/inicioRecyclerConsumos"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
Related
I have 2 RecyclerViews that uses the same XML file to inflate views through the adapter.
One RecyclerView does catch clicks while the other doesn't.
The first RecyclerView is on another fragment and the code is similar to the second RecyclerView.
I have tried a lot of changes to the XML file(MaterialCardView) such as removing clickable attribute or changing the layout_weight to be 1 on the card but all of them didn't work.
Also, I can't understand why it would work only on 1 with the same settings on the other.
Here is the code for the second part which is not working:
Fragment - section of matter
list = view.findViewById(R.id.user_display_details_rv); //Getting the RecyclerView
list.setHasFixedSize(true);
int numOfColumns = 2;
list.setLayoutManager(new GridLayoutManager(getContext(), numOfColumns,GridLayoutManager.VERTICAL,false));
adapter = new UserDisplayDetailsAdapter(viewModel,getLayoutInflater());
list.setAdapter(adapter);
list.addItemDecoration(new RecyclerView.ItemDecoration() {
#Override
public void getItemOffsets(#NonNull Rect outRect, #NonNull View view, #NonNull RecyclerView parent, #NonNull RecyclerView.State state) {
outRect.set(5,20,5,20);
}
});
adapter.setOnItemClickListener((v,pos)->{
String pollId = Objects.requireNonNull(viewModel.getUserFilledPolls().get(pos).getPollId());
Navigation.findNavController(v).navigate(FragmentUserDisplayDetailsDirections.actionFragmentUserDisplayDetailsToFragmentOtherUserPoll(pollId,userId));
});
Adapter
public class UserDisplayDetailsAdapter extends RecyclerView.Adapter<UserDisplayDetailsHolder> {
UserDisplayDetailsViewModel viewModel;
LayoutInflater layoutInflater;
OnItemClickListener onItemClickListener;
public UserDisplayDetailsAdapter(UserDisplayDetailsViewModel viewModel, LayoutInflater layoutInflater) {
this.viewModel = viewModel;
this.layoutInflater = layoutInflater;
}
#NonNull
#Override
public UserDisplayDetailsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) MyApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.poll_list_square,parent,false);
return new UserDisplayDetailsHolder(view,onItemClickListener);
}
#Override
public void onBindViewHolder(#NonNull UserDisplayDetailsHolder holder, int position) {
Poll poll = Objects.requireNonNull(viewModel.getUserFilledPolls().get(position));
holder.bind(poll);
}
#Override
public int getItemCount() {
if(viewModel.getUserFilledPolls() == null){
return 0;
}
return viewModel.getUserFilledPolls().size();
}
public void setOnItemClickListener(OnItemClickListener listener){
this.onItemClickListener = listener;
}
}
Holder
public class UserDisplayDetailsHolder extends RecyclerView.ViewHolder {
MaterialTextView pollsName;
ShapeableImageView icon;
public UserDisplayDetailsHolder(#NonNull View itemView, OnItemClickListener onItemClickListener) {
super(itemView);
pollsName = itemView.findViewById(R.id.homescr_poll_pollName);
icon=itemView.findViewById(R.id.homescr_poll_icon);
itemView.setOnClickListener(v->{
int pos = getAdapterPosition();
onItemClickListener.onItemClick(v,pos);
});
}
public void bind(Poll poll) {
pollsName.setText(poll.getPollName());
}
}
Common XML
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
android:id="#+id/homescr_btn_poll"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:layout_width="110dp"
android:layout_height="90dp"
android:layout_gravity="center"
app:cardBackgroundColor="#color/primeOrng"
app:cardCornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeWidth="2dp"
android:theme="#style/Theme.MaterialComponents.Light">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="horizontal">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_mainImage"
android:layout_width="60dp"
android:layout_height="40dp"
android:scaleType="fitStart"
app:strokeWidth="0dp"
app:srcCompat="#drawable/ic_poll" />
<Space
android:id="#+id/homescr_poll_space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_icon"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="end"
app:srcCompat="#drawable/ic_feed_arrow"
app:strokeWidth="0dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homescr_poll_pollName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:text="#string/poll_name"
android:textAppearance="?attr/textAppearanceHeadline6"
android:textColor="#color/white"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_doneImage"
android:layout_width="60dp"
android:layout_height="50dp"
android:visibility="gone"
app:srcCompat="#drawable/done_nobg" />
</com.google.android.material.card.MaterialCardView>
Working Fragment XML(Catching clicks on RecyclerView)
<?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="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
app:cardElevation="0dp"
app:strokeColor="#color/stroke_color">
tools:context=".FragmentHomeScreen">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homeScreen_logo"
android:layout_width="306dp"
android:layout_height="160dp"
android:src="#drawable/logo__nobg_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homeScr_text_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="Hello, "
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeScreen_logo" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homeScr_text_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="80dp"
android:fontFamily="sans-serif-black"
android:gravity="start"
android:text="User Name"
android:maxLines="1"
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/homeScr_text_title"
app:layout_constraintTop_toBottomOf="#+id/homeScreen_logo" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/home_layout_const"
android:layout_width="350dp"
android:layout_height="250dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="10dp"
android:foregroundGravity="center_horizontal"
android:paddingLeft="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeScr_text_name">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/home_layout_poll_refresh"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_poll_rv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="#color/white"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_line"
android:layout_width="350dp"
android:layout_height="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="90dp"
android:backgroundTint="#978F8F"
app:cornerRadius="100px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_feed"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/black"
android:drawableTop="#drawable/ic_feed"
android:fontFamily="sans-serif-medium"
android:text="FEED"
android:textColor="#color/primeOrng"
android:textSize="14dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/homescr_btn_map"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homescr_btn_line"
app:strokeColor="#color/black"
app:strokeWidth="2dp" />
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_map"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/black"
android:drawableTop="#drawable/ic_map"
android:fontFamily="sans-serif-medium"
android:text="#string/map"
android:textColor="#color/primeOrng"
android:textSize="14dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/homescr_btn_feed"
app:layout_constraintTop_toBottomOf="#+id/homescr_btn_line"
app:strokeColor="#color/black"
app:strokeWidth="2dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
NOT Working Fragment XML(NOT Catching clicks on RecyclerView)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:background="#color/black"
android:scrollbars="vertical"
android:scrollbarSize="3dp"
android:scrollbarStyle="insideInset"
tools:context=".feed.FragmentUserDisplayDetails">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/user_display_details_img_main"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.App.CornerSize50Percent"
app:srcCompat="#drawable/avatar"
app:strokeColor="#color/white"
app:strokeWidth="1dp" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="User Name"
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_display_details_img_main" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/user_dusplay_details_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_display_details_txt_username">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:drawableStart="#drawable/ic_account"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="#string/email"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/ic_white_location"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:maxLines="2"
android:paddingLeft="20dp"
android:text="address"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_education"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/ic_education"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="education"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/sex_icon"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="SEX"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/user_display_details_poll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/textviewbg">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/user_display_details_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.button.MaterialButton
android:id="#+id/feed_back_btn"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:backgroundTint="#color/black"
android:fontFamily="sans-serif"
android:text="BACK "
android:textSize="20sp"
app:cornerRadius="35dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_dusplay_details_layout"
app:strokeColor="#color/primeOrng"
app:strokeWidth="1dp" />
<ProgressBar
android:id="#+id/user_display_details_progress_bar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I have created one XML with 4 CardView contains 4 RadioButton and other layouts as follow:
fragment_list_of_transport.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<android.support.v4.widget.NestedScrollView 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">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_1"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_1"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_1" />
<ImageView
android:id="#+id/image_truck_1"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_1"
app:layout_constraintStart_toEndOf="#+id/radio_button_1"
app:layout_constraintTop_toTopOf="#+id/title_text_view_1"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_1"
app:layout_constraintTop_toBottomOf="#+id/image_view_1" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_1"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/parent_card_2"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_1">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_2"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_2" />
<ImageView
android:id="#+id/image_truck_2"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_2"
app:layout_constraintStart_toEndOf="#+id/radio_button_2"
app:layout_constraintTop_toTopOf="#+id/title_text_view_2"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_2"
app:layout_constraintTop_toBottomOf="#+id/image_view_2" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_2"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_3"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_2">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_3"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_3" />
<ImageView
android:id="#+id/image_truck_3"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_3"
app:layout_constraintStart_toEndOf="#+id/radio_button_3"
app:layout_constraintTop_toTopOf="#+id/title_text_view_3"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_3"
app:layout_constraintTop_toBottomOf="#+id/image_view_3" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_3"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_4"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
android:layout_marginBottom="#dimen/_10sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_3">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_4"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_4" />
<ImageView
android:id="#+id/image_truck_4"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_4"
app:layout_constraintStart_toEndOf="#+id/radio_button_4"
app:layout_constraintTop_toTopOf="#+id/title_text_view_4"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_4"
app:layout_constraintTop_toBottomOf="#+id/image_view_4" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_4"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Output:
I want to manage RadioButton on click of both CardView and RadioButton , I have used following code:
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
mBinding.radioButton1.setChecked(true);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_2:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(true);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_3:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(true);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_4:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(true);
break;
}
}
}
Is there any best way to manage it?
I don't easiest way then following (If you have easy way then I will accept it.):
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
mBinding.radioButton1.setOnClickListener(this);
mBinding.radioButton2.setOnClickListener(this);
mBinding.radioButton3.setOnClickListener(this);
mBinding.radioButton4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
case R.id.radio_button_1:
clickedRadioButton(mBinding.radioButton1);
break;
case R.id.parent_card_2:
case R.id.radio_button_2:
clickedRadioButton(mBinding.radioButton2);
break;
case R.id.parent_card_3:
case R.id.radio_button_3:
clickedRadioButton(mBinding.radioButton3);
break;
case R.id.parent_card_4:
case R.id.radio_button_4:
clickedRadioButton(mBinding.radioButton4);
break;
}
}
private void clickedRadioButton(RadioButton radioButton) {
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
radioButton.setChecked(true);
}
}
If anyone has easiest way then this, please post answer. I will accept.
I am making a sign up and sign in form using TabLayout. The height of the signup form will be long, but due to some reasons I am not able to add ScrollView inside fragment.
Here is what I am doing: https://imgur.com/9p42i43
Here is my layout Main Activity
<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"
android:background="#color/appBackground"
tools:context=".LoginActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/secondaryColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/logo_view"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#color/secondaryColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar2" />
<android.support.design.widget.TabLayout
android:id="#+id/signin_signup_tab_lay"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/secondaryColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/logo_view"
app:tabBackground="#drawable/curve_login"
app:tabIndicatorColor="#color/yellow_btn"
app:tabSelectedTextColor="#color/primaryColor"
app:tabTextAppearance="#style/tabstyle"
app:tabTextColor="#7d98c3">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/signin_signup_tab_lay"></android.support.v4.view.ViewPager>
</android.support.constraint.ConstraintLayout>
Java Main Activity
package com.example.mobilestyx.fantasy_arena;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
TabLayout tabLayout;
private int[] tabIcons = {
R.drawable.curve_login,
R.drawable.curve_login
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
tabLayout = (TabLayout) findViewById(R.id.signin_signup_tab_lay);
tabLayout.addTab(tabLayout.newTab().setText("Signin"));
tabLayout.addTab(tabLayout.newTab().setText("Signup"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
//
// setupTabIcons();
final ViewPager viewPager = (ViewPager)findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(),tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
private void setupTabIcons() {
TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabLayout.getTabAt(0).setCustomView(tabOne);
TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabLayout.getTabAt(1).setCustomView(tabTwo);
}}
Here is my fragment layout
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/constraint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:context=".SignupFragment">
<!-- TODO: Update blank fragment layout -->
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="#drawable/login_fb_btn"
android:fontFamily="#font/mavenpro_regular_font"
android:text="Signup with Facebook"
android:textColor="#ffffff"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:fontFamily="#font/mavenpro_regular_font"
android:gravity="center"
android:text="OR"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button3" />
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2">
<EditText
android:id="#+id/signup_name_et"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/startborder_input"
android:ems="10"
android:fontFamily="#font/mavenpro_regular_font"
android:hint="John Doe"
android:inputType="textPersonName"
android:paddingLeft="15dp" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Full Name"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Email"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView2" />
<android.support.v7.widget.CardView
android:id="#+id/cardView3"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3">
<EditText
android:id="#+id/signup_email_et"
style="#style/MavenproEdittextStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/startborder_input"
android:ems="10"
android:hint="johndoe#mail.com"
android:inputType="textEmailAddress"
android:paddingLeft="15dp" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Phone"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView3" />
<android.support.v7.widget.CardView
android:id="#+id/cardView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4">
<EditText
android:id="#+id/signup_phone_et"
style="#style/MavenproEdittextStyle"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/startborder_input"
android:ems="10"
android:hint="000-000-0000"
android:inputType="number"
android:paddingLeft="15dp"
android:textColor="#000000" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Gender"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView4" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5">
<RadioButton
android:id="#+id/signup_gender_m_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Male" />
<RadioButton
android:id="#+id/signup_gender_f_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Female" />
</RadioGroup>
<TextView
android:id="#+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="DOB"
android:textColor="#000000"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioGroup" />
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="28dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6">
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date" />
</android.support.v7.widget.CardView></android.support.constraint.ConstraintLayout>
Java Fragment
package com.example.mobilestyx.fantasy_arena;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {#link Fragment} subclass.
*/
public class SignupFragment extends Fragment {
public SignupFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_signup, container, false);
}
}
While using Constraint Layout, try using NestedScrollView for scrolling.
Make sure your ScrollView has constraints to parent which is ConstraintLayout view in each edges.
I'm trying to create a layout for my Fragment . Here is my xml layout.
Fragment_profil.xml
<FrameLayout 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"
tools:context="com.example.boby.srsly.ProfilFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
But, when i run it i only see white background, i mean because this is bottomnavigationview i only can see the navigation from what i write above. How can i fix it, is there something missing ? Thanks in advance and sorry for my bad english.
Here is my ProfilFragment.java
public class ProfilFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_profil, container, false);
SharedPreferences mPrefs = this.getActivity().getSharedPreferences("userinfoafterlogin", MODE_PRIVATE); //add key
String response = mPrefs.getString("userinfo", null);
try{
JSONObject json = new JSONObject(response);
json = (JSONObject)json.get("nameValuePairs");
json = (JSONObject)json.get("userData");
json = (JSONObject)json.get("nameValuePairs");
String fullname = (String)json.get("fullname");
String phone = (String)json.get("phone");
String desc = (String)json.get("Deskripsi");
TextView labelfullname = (TextView)v.findViewById(R.id.fullnametext);
TextView labeltelp = (TextView)v.findViewById(R.id.notelptext);
TextView labeldesc = (TextView)v.findViewById(R.id.deskripsitxt);
labelfullname.setText(fullname);
labeltelp.setText(phone);
labeldesc.setText(desc);
return v;
}catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
return v;
}
}
}
Try this
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
OUTPUT
I hope you can help me out with a problem. I tried to google it, and looked through the topics here, but was unable to find an answer.
I recently changed my layouts to ConstraintLayouts, and this have been working great so far. My problem however is i had some DialogFragments displaying a LinearLayout, and when i changed it to ConstraintLayout i only shows a faded overlay, but non of the elements in the layout. If i hardcode the width and height to something like 100dp, it will display that area. When i try match_parent or any other combination the same problem applies. I also tried setting the height and width to the device height and width but still with no luck.
In the onCreateView in my CreateWeddingMetadataFragment i have:
createButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "Show message dialog");
FragmentManager fm = getFragmentManager();
CreateWeddingMetadataDialogFragment welcomeMessageDialog = new CreateWeddingMetadataDialogFragment();
welcomeMessageDialog.show(fm, "metadate_fragment_dialog");
welcomeMessageDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
}
});
In my CreateWeddingMetadataFragmentDialog i have:
public class CreateWeddingMetadataDialogFragment extends DialogFragment{
private static final String TAG = CreateWeddingMetadataDialogFragment.class.getSimpleName();
public Button setupNow, setupLater;
public TextView mTest;
public ConstraintLayout parentLayout;
private DialogInterface.OnDismissListener onDismissListener;
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
this.onDismissListener = onDismissListener;
}
#Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (onDismissListener != null) {
onDismissListener.onDismiss(dialog);
}
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "I was called");
}
public CreateWeddingMetadataDialogFragment(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.create_welcome_message_view, container);
setupNow = (Button) view.findViewById(R.id.setupNowButton);
setupLater = (Button) view.findViewById(R.id.setupLaterButton);
mTest = (TextView) view.findViewById(R.id.welcomeMessageTitle);
parentLayout = (ConstraintLayout) view.findViewById(R.id.clWelcomeMessage);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
parentLayout.setMinimumWidth(width);
parentLayout.setMinimumHeight(height);
mTest.setText("Test");
Log.d(TAG, "I was called onCreateView" + mTest);
setupNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Go to metadate page (Hide this dialog)
}
});
setupLater.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Go to signin page and create the wedding
}
});
return view;
}
}
That is with my current try of setting it to the device size.
And here is the create_welcome_message_view:
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/clWelcomeMessage">
<Button
android:text="DET GØR JEG SENERE"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/setupLaterButton"
app:layout_constraintTop_toTopOf="#+id/guideline19"
app:layout_constraintBottom_toTopOf="#+id/guideline20"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
android:background="#drawable/border"
android:layout_marginTop="2dp"
android:textColor="#color/colorPrimaryDark"/>
<Button
android:text="JEG VIL OPSÆTTE DEN NU"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/setupNowButton"
app:layout_constraintTop_toTopOf="#+id/guideline12"
app:layout_constraintBottom_toTopOf="#+id/guideline19"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
android:background="#color/colorPrimaryDark"
android:layout_marginBottom="2dp"
android:textColor="#color/White"/>
<TextView
android:text="EN PERSONLIG VELKOMST"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/welcomeMessageTitle"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
app:layout_constraintBottom_toTopOf="#+id/textView5"
android:layout_marginBottom="8dp"
android:textAlignment="center"
android:textSize="16sp"/>
<TextView
android:text="Nu skal I definere den velkomst, som jeres gæster får i appen. I kan skrive navnet på brylluppet, en hlsen og har mulighed at vælge et coverbillede"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/textView5"
app:layout_constraintTop_toTopOf="#+id/guideline14"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
android:layout_marginBottom="8dp"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
android:textAlignment="center"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline12"
android:orientation="horizontal"
tools:layout_editor_absoluteY="204dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.4"/>
<TextView
android:text="Du vil altid kunne ændre din opsætning af velkomsten i din brugerprofil."
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/textView6"
app:layout_constraintBottom_toTopOf="#+id/guideline12"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="#+id/guideline15"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
android:textAlignment="center"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="1.0"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline14"
android:orientation="horizontal"
tools:layout_editor_absoluteY="51dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.1"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline15"
android:orientation="horizontal"
tools:layout_editor_absoluteY="153dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.3"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline19"
android:orientation="horizontal"
tools:layout_editor_absoluteY="255dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.5"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline20"
android:orientation="horizontal"
tools:layout_editor_absoluteY="305dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.6"/>
</android.support.constraint.ConstraintLayout>
If you need any additional information let me know, and thanks in advance.
This works fine - check out
1) Its good practice to arrange items in order where possible in XML too as visualized. Just to easily comprehend later.
2) Its looks every other element is constraining itself to others height and width and mostly resulting in 0 height and width. Watch out for 0dp and wrap_content on LayoutParams.
3) Take support of Vertical Bias too.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/clWelcomeMessage"
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="wrap_content"
android:orientation="vertical">
<android.support.constraint.Guideline
android:id="#+id/guideline_ver_16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="#dimen/sixteenDP"/>
<android.support.constraint.Guideline
android:id="#+id/guideline_ver_end_16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="#dimen/sixteenDP"/>
<TextView
android:id="#+id/welcomeMessageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="32dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:text="EN PERSONLIG VELKOMST"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#+id/textView5"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.constraint.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1"/>
<android.support.constraint.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.2"/>
<TextView
android:id="#+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Nu skal I definere den velkomst, som jeres gæster får i
appen.
I kan skrive navnet på brylluppet, en hlsen og har mulighed at vælge et
coverbillede"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="#+id/guideline_ver_end_16"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/guideline_ver_16"
app:layout_constraintTop_toBottomOf="#+id/guideline2"/>
<TextView
android:id="#+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Du vil altid kunne ændre din opsætning af velkomsten i din
brugerprofil."
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/setupNowButton"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="#+id/guideline_ver_16"
app:layout_constraintRight_toRightOf="#+id/guideline_ver_end_16"
app:layout_constraintTop_toBottomOf="#+id/textView5"/>
<Button
android:id="#+id/setupNowButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#color/colorPrimaryDark"
android:text="JEG VIL OPSÆTTE DEN NU"
android:textColor="#color/White"
app:layout_constraintBottom_toTopOf="#+id/setupLaterButton"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
app:layout_constraintVertical_bias="1.0"/>
<android.support.constraint.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.6"/>
<Button
android:id="#+id/setupLaterButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:text="DET GØR JEG SENERE"
android:background="#drawable/border"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline6"
app:layout_constraintVertical_bias="1.0"/>
</android.support.constraint.ConstraintLayout>
Also, app:layout_constraintWidth_default="wrap" (with width set to 0dp). If set, the widget will have the same size as if using wrap_content, but will be limited by constraints (i.e. it won't expand beyond them).
Supporting resource