How to not repeat recycle view inside nested layout? - android

I am trying to create a nested recycle view. So far i have a parent recycle view and under this i have a child recycle view. The problem that i am having is my child recycle view continues to be recycled with my parent recycle view. I do not want this i would like the child recycle view to only be recycled once. Does any one know how to go about fixing this. I understand this might sound a little confusing, but an example of what i want is instagram news feed. The top of the app have circle image views with your followers stories which can be swiped and the bottom have the news feed itself, in my case my app loads the user stories continuously under the news feed as i continue to scroll users stories are being continuously recycled under the news feed post.
Main UI with parent recycleView
<?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="#FFFFFF">
<androidx.appcompat.widget.Toolbar
android:id="#+id/newsFeedToolBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="12dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/backButton"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="left"
android:background="#drawable/ic_arrow_back_black_24dp"
android:onClick="backImageView"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="15dp" />
</androidx.appcompat.widget.Toolbar>
<SearchView
android:id="#+id/searchView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="6dp"
android:background="#FFFFFF"
android:iconifiedByDefault="false"
android:queryHint="Search"
app:layout_constraintBottom_toBottomOf="#+id/newsFeedToolBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/newsFeedToolBar"
app:layout_constraintTop_toTopOf="#+id/newsFeedToolBar"
app:searchIcon="#null" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/newsRecycleVIew"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/News"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/News"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="News"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.045"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/searchView" />
</androidx.constraintlayout.widget.ConstraintLayout>
*Row Item for parent recycleview added child recycle view*
<?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/constraintlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/newsThumbNail"
android:layout_width="0dp"
android:layout_height="200dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.448"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="#+id/newsTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Dangerous fire is out of control at 24 and park"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="#+id/newsThumbNail"
app:layout_constraintStart_toStartOf="#+id/newsThumbNail"
app:layout_constraintTop_toBottomOf="#+id/newsThumbNail" />
<TextView
android:id="#+id/newsBody"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Some text is here"
app:layout_constraintEnd_toEndOf="#+id/newsTitle"
app:layout_constraintStart_toStartOf="#+id/newsTitle"
app:layout_constraintTop_toBottomOf="#+id/newsTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/earningsRecycleView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.448"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Upcoming Earnings"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.045"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView" />
</androidx.constraintlayout.widget.ConstraintLayout>
**Parent RecycleView adapter **
public class SearchStockAdapter extends RecyclerView.Adapter<SearchStockAdapter.SearchStocksViewHolder> {
private Context context;
private ArrayList<News_Model> stockInformaiton;
private RequestQueue requestQueue;
private SearchStockSubAdapter searchStockSubAdapter;
private RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
public SearchStockAdapter(Context context, ArrayList<News_Model> stockInformaiton) {
this.context = context;
this.stockInformaiton = stockInformaiton;
}
#NonNull
#Override
public SearchStocksViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.search_stock_row, viewGroup, false);
requestQueue = Volley.newRequestQueue(context);
return new SearchStocksViewHolder(view);
}
//Loads data into views
#Override
public void onBindViewHolder(#NonNull SearchStocksViewHolder viewHolder, int i) {
viewHolder.newsTitle.setText(stockInformaiton.get(i).getTitle());
viewHolder.newsBody.setText(stockInformaiton.get(i).getDescription());
Glide.with(this.context).asBitmap().load(stockInformaiton.get(i).getUrlToImage()).into(viewHolder.newsThumbImage);
//Second recycle view...
LinearLayoutManager layoutManager = new LinearLayoutManager(
viewHolder.upcomingEarningsRecycleView.getContext(),
LinearLayoutManager.HORIZONTAL,
false
);
layoutManager.setInitialPrefetchItemCount(stockInformaiton.size());
//second recycle view..
SearchStockSubAdapter stockSubAdapter = new SearchStockSubAdapter(context, stockInformaiton);
viewHolder.upcomingEarningsRecycleView.setLayoutManager(layoutManager);
viewHolder.upcomingEarningsRecycleView.setAdapter(stockSubAdapter);
viewHolder.upcomingEarningsRecycleView.setHasFixedSize(true);
viewHolder.upcomingEarningsRecycleView.setRecycledViewPool(viewPool);
}
#Override
public int getItemCount() {
return stockInformaiton.size();
}
static class SearchStocksViewHolder extends RecyclerView.ViewHolder {
private TextView newsTitle, newsBody;
private ImageView newsThumbImage;
private RecyclerView upcomingEarningsRecycleView;
public SearchStocksViewHolder(#NonNull View itemView) {
super(itemView);
//newsThumbnail = itemView.findViewById(R.id.newsThumbNail);
newsTitle = itemView.findViewById(R.id.newsTitle);
newsBody = itemView.findViewById(R.id.newsBody);
newsThumbImage = itemView.findViewById(R.id.newsThumbNail);
upcomingEarningsRecycleView = itemView.findViewById(R.id.earningsRecycleView);
}
}
}

Related

got E/No adapter attached; skipping layout even when I attach a Layoutmanager and the adapter

I try to create a recyclerview for my gallery photo and video, I'm sur the data is correctly collected, an adapter is created and attached to my recycler view before the error.
I created the recyclerview as follow :
fileList = FileUtils.filesInGaleryFolder
itemAdapter = GalerieAdapter(this, fileList)
galeriebind.recyclerGallery.layoutManager = GridLayoutManager(this, 3)
galeriebind.recyclerGallery.adapter = itemAdapter
Here is my adapter class:
class GalerieAdapter(ctx: Activity, items: List<File>) : RecyclerView.Adapter<GalerieAdapter.ViewHolder>() {
//--- VARIABLES -----//
var ctx: Context = ctx
var items: List<File> = items
var esVideo = false
/*****
* This method is called right when the adapter is created and is used to initialize your ViewHolder(s).
*****/
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.gallery_item, parent, false)
return ViewHolder(view)
}
Below you will also find my xml for the activity and the adapter:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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:fillViewport="true"
tools:context=".Galerie">
<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="#drawable/bg_home"
tools:context=".Galerie">
<ImageView
android:id="#+id/imageTitle"
android:layout_width="230dp"
android:layout_height="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/logo_home" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#color/detailsgrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageTitle" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_gallery"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="55dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/view"
app:layout_constraintStart_toStartOf="#+id/view"
app:layout_constraintTop_toBottomOf="#+id/view" />
<ImageButton
android:id="#+id/backbutton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="24dp"
android:layout_marginTop="5dp"
android:background="#color/transparent"
android:padding="6dp"
android:scaleType="fitXY"
android:src="#drawable/ic_arrow_left"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="#+id/imageTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/imageTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
and the one for the adapter:
<?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/container"
android:layout_width="178dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:background="#drawable/bt_galery_item_selector">
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="16dp"
android:fontFamily="#font/nunito_bold"
android:textColor="#color/BLACK"
app:layout_constraintBottom_toTopOf="#+id/hour"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
tools:text="12/12/2019" />
<TextView
android:id="#+id/hour"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
tools:text="20:45:03" />
<View
android:id="#+id/bg_categoria"
android:layout_width="0dp"
android:layout_height="24dp"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="48dp"
android:background="#drawable/rounded_shape"
android:backgroundTint="#color/greenbutton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/categoria"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:fontFamily="#font/nunito_bold"
android:gravity="start|right|left|end"
android:textColor="#color/WHITE"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="#+id/bg_categoria"
app:layout_constraintEnd_toEndOf="#+id/bg_categoria"
app:layout_constraintStart_toEndOf="#+id/imgCategoria"
app:layout_constraintTop_toTopOf="#+id/bg_categoria"
tools:text="VIDEO" />
<ImageView
android:id="#+id/imgCategoria"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toBottomOf="#+id/bg_categoria"
app:layout_constraintStart_toStartOf="#+id/bg_categoria"
app:layout_constraintTop_toTopOf="#+id/bg_categoria"
app:srcCompat="#drawable/ic_video_label" />
</androidx.constraintlayout.widget.ConstraintLayout>
I saw that the problem can be related to the lack of grid layout, but I initialized one and passed it to the recyclerview, and I still get the error "No adapter attached; skipping layout" and no item are displayed. I also found it can be related to asynchronous call, but i don't think there is any asynchronous in my case as it's in the OnCreate(). and event with the notifyDataSetChanged() but it doesn't solve the problem.
I also try to initialize the adapter first then init data as following:
itemAdapter = GalerieAdapter(this, fileList)
galeriebind.recyclerGallery.adapter = itemAdapter
fileList = FileUtils.filesInGaleryFolder
itemAdapter!!.setFiles(fileList)
I checked the data in galeriebind.recyclerGallery.adapter is correctly updated and i call the notifyDataSetChanged() in the setFiles() method
I finally found out the answer, the problem is coming from my binding,
I just replaced :
itemAdapter = GalerieAdapter(this, fileList)
galeriebind.recyclerGallery.adapter = itemAdapter
fileList = FileUtils.filesInGaleryFolder
itemAdapter!!.setFiles(fileList)
by:
itemAdapter = GalerieAdapter(Activity(), fileList)
var recyclerview = findViewById<RecyclerView>(R.id.recycler_gallery)
recyclerview.adapter = itemAdapter
fileList = FileUtils.filesInGaleryFolder
itemAdapter.setFiles(fileList)
val glm = GridLayoutManager(this, 3)
glm.orientation = GridLayoutManager.HORIZONTAL
recyclerview.layoutManager = glm
Using the findviewbyID solved it

Recycleview custom layout constraint are changing for each inflated view causing problems

I have a recyclerview that inflates data fetched from json.
The issue I am facing are design issues - sometimes the text is aligned correctly and the image is shown and sometimes the text is too long, causing what I think is for the image not to be shown.
here is my 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="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="395dp"
android:layout_height="170dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="#335634"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroTitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroDescription"
android:layout_width="200dp"
android:breakStrategy="simple"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="TextView"
android:textAlignment="center"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toBottomOf="#+id/heroTitle" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
and here is my adapter:
public class HeroesAdapter extends RecyclerView.Adapter<HeroesAdapter.HeroesViewHolder> {
private List<Hero> heroList;
public HeroesAdapter(List<Hero> heroList) {
this.heroList = heroList;
}
#NonNull
#Override
public HeroesViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View rowView = LayoutInflater.from(parent.getContext()).inflate(R.layout.hero_cell, parent, false);
return new HeroesViewHolder(rowView);
}
#Override
public void onBindViewHolder(#NonNull HeroesViewHolder holder, int position) {
Hero currentHero = heroList.get(position);
String str = String.join(",", currentHero.abilities);
holder.heroTitle.setText(currentHero.title);
holder.heroAbilties.setText(str);
Picasso.get().load(currentHero.image).resize(500,500).into(holder.heroesImage);
}
#Override
public int getItemCount() {
return heroList.size();
}
public static class HeroesViewHolder extends RecyclerView.ViewHolder {
ImageView heroesImage;
TextView heroTitle;
TextView heroAbilties;
public HeroesViewHolder(#NonNull View itemView) {
super(itemView);
heroesImage = itemView.findViewById(R.id.heroImage);
heroTitle = itemView.findViewById(R.id.heroTitle);
heroAbilties = itemView.findViewById(R.id.heroDescription);
}
}
}
This is the result I am getting and this is the wanted result.
the issues I am facing are:
making each row have a clean design and act the same for all.
images are sometimes shown, sometimes not.
bottom view is "half in screen" and half out of screen.
By using LinearLayout you can design your hero_cell that will give you the desirable output. as I do it for now.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
android:padding="10dp"
android:background="#335634"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:src="#drawable/logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:background="#335634"
android:layout_marginLeft="20dp"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/heroTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textSize="25dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/heroDescription"
android:layout_width="match_parent"
android:breakStrategy="simple"
android:layout_height="wrap_content"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="TextView"
android:textSize="18dp" />
</LinearLayout>
According to your expectation, you should use card-view and I've updated the layout. Please check
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
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_margin="10dp"
app:cardCornerRadius="10dp"
android:elevation="10dp"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="395dp"
android:layout_height="170dp"
android:background="#fff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/heroImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroTitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:text="Hero Title"
android:textColor="#000"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/heroDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/heroDescription"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:autoSizeMaxTextSize="25dp"
android:autoSizeMinTextSize="15dp"
android:breakStrategy="simple"
android:text="TextView"
android:textColor="#444"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/heroImage"
app:layout_constraintTop_toBottomOf="#+id/heroTitle" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

how to show drop down of AutoCompleteTextView behind of a view?

I used an AutoCompleteTextView in my Service. after user type in AutoCompleteTextView, a drop down shown like this:
drop down is shown top of service layout but what I want is shown behind of that like this:
service use this 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:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<View
android:id="#+id/bg"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/floating_service_bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<android.support.constraint.ConstraintLayout
android:id="#+id/collapse_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="#id/bg"
app:layout_constraintLeft_toLeftOf="#id/bg"
app:layout_constraintTop_toTopOf="#id/bg"
>
<ImageView
android:id="#+id/icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="8dp"
android:src="#drawable/star"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="#+id/close_btn"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/ic_close"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription"/>
</android.support.constraint.ConstraintLayout>
<View
android:id="#+id/drop_down_anchor"
android:layout_width="0dp"
android:layout_height="0.5dp"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<LinearLayout
android:id="#+id/expanded_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#id/bg"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toRightOf="#id/collapse_view"
app:layout_constraintRight_toRightOf="#id/bg"
app:layout_constraintTop_toTopOf="#id/bg">
<AutoCompleteTextView
android:id="#+id/searchBox"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:background="#color/transparent"
android:dropDownAnchor="#id/drop_down_anchor"
android:gravity="left"
android:hint="#string/searchboxHint"
android:imeOptions="actionDone"
android:inputType="textPhonetic"
android:padding="15dip"
android:selectAllOnFocus="false"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#a5a5a5"
android:textIsSelectable="true"
android:textSize="16sp"
/>
<ImageView
android:id="#+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="#drawable/ic_search_24dp"
android:visibility="visible"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
and DropDownAdapter class:
class DropDownAdapter extends ArrayAdapter<String> {
ArrayList<String> wordList;
ArrayList<String> meanList;
public DropDownAdapter(ArrayList<String> words, ArrayList<String> means) {
super(context, R.layout.drop_down_layout, words);
this.wordList = words;
this.meanList = means;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
View rowView = (View) inflater.inflate(R.layout.drop_down_layout,
parent, false);
TextView leftTextView = (TextView) rowView.findViewById(R.id.item_word);
TextView rightTextView = (TextView) rowView.findViewById(R.id.item_mean);
LinearLayout dropDownItem = (LinearLayout) rowView.findViewById(R.id.drop_down_item);
final int pos = position;
leftTextView.setText(wordList.get(pos));
rightTextView.setText(meanList.get(pos));
return rowView;
}
}
can you suggest me a solution, please?

Android Recyclerview items in ConstraintLayout doesn't display

I have a Constraint Layout which has RecyclerViews and some TextViews.All of the Recyclerview's visibility has been to set to 'gone' except last one.I have set that RecyclerView's width and height to match_constraint.The orientation of RecyclerView is Horizontal. The items are also have Constraint Layout as their parent. At runtime the items are not displayed.
Xml:
home_lyt_children.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.view.ViewPager
android:layout_width="0dp"
android:layout_height="150dp"
android:id="#+id/pager"
android:layout_margin="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
</android.support.v4.view.ViewPager>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="SHOP BY CATEGORY"
android:textAlignment="center"
android:textSize="25sp"
android:id="#+id/ctgry_lbl"
app:layout_constraintTop_toBottomOf="#id/pager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v7.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/ctgry_recycler"
android:visibility="gone"
app:layout_constraintStart_toStartOf="#id/pager"
app:layout_constraintEnd_toEndOf="#id/pager"
app:layout_constraintTop_toBottomOf="#id/ctgry_lbl"
>
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="POPULAR PRODUCTS"
android:textAlignment="center"
android:textSize="25sp"
android:id="#+id/poplr_lbl"
app:layout_constraintTop_toBottomOf="#id/ctgry_recycler"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v7.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/poplr_recycler"
android:visibility="gone"
app:layout_constraintStart_toStartOf="#id/pager"
app:layout_constraintEnd_toEndOf="#id/pager"
app:layout_constraintTop_toBottomOf="#id/poplr_lbl">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="NEW PRODUCTS"
android:textAlignment="center"
android:textSize="25sp"
android:id="#+id/newprdct_lbl"
app:layout_constraintTop_toBottomOf="#id/poplr_recycler"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v7.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/newprdcts_recycler"
android:visibility="gone"
app:layout_constraintStart_toStartOf="#id/pager"
app:layout_constraintEnd_toEndOf="#id/pager"
app:layout_constraintTop_toBottomOf="#id/newprdct_lbl">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="RECOMMENDED FOR YOU"
android:textAlignment="center"
android:textSize="25sp"
android:id="#+id/recommended_lbl"
app:layout_constraintTop_toBottomOf="#id/newprdcts_recycler"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recommended_recycler"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#id/pager"
app:layout_constraintStart_toStartOf="#id/pager"
app:layout_constraintTop_toBottomOf="#id/recommended_lbl">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
home_recomended_prdcts_item.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">
<ImageView
android:id="#+id/recomm_prdct_img"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#color/colorPrimary"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/recomm_prdct_itemtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Oppo"
android:textAlignment="center"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="#+id/recomm_prdct_img"
app:layout_constraintStart_toStartOf="#+id/recomm_prdct_img"
app:layout_constraintTop_toBottomOf="#+id/recomm_prdct_img" />
<TextView
android:id="#+id/recomm_prdct_itemdesc"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="8dp"
android:text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum "
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/recomm_prdct_img"
app:layout_constraintStart_toStartOf="#+id/recomm_prdct_img"
app:layout_constraintTop_toBottomOf="#+id/recomm_prdct_itemtitle" />
</android.support.constraint.ConstraintLayout>
Code:
adapter:
public class HomeRecommendedProductsAdapter extends RecyclerView.Adapter<HomeRecommendedProductsAdapter.HomeRecommendedViewHolder> {
#NonNull
#Override
public HomeRecommendedViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
return new HomeRecommendedViewHolder(LayoutInflater.from(viewGroup.getContext()).
inflate(R.layout.home_recomended_prdcts_item,viewGroup,false));
}
#Override
public void onBindViewHolder(#NonNull HomeRecommendedViewHolder popularproductsViewHolder, int i) {
popularproductsViewHolder.recomm_prdct_itemtitle.setText("Google Pixel");
popularproductsViewHolder.recomm_prdct_itemdesc.setText("google Pixel Rocks google Pixel Rocks google Pixel Rocks google Pixel Rocks google Pixel Rocks google Pixel Rocks");
}
#Override
public int getItemCount() {
return 10;
}
public class HomeRecommendedViewHolder extends RecyclerView.ViewHolder{
private ImageView recomm_prdct_img;
private TextView recomm_prdct_itemtitle,recomm_prdct_itemdesc;
public HomeRecommendedViewHolder(#NonNull View itemView) {
super(itemView);
initializeIds(itemView);
}
private void initializeIds(View view) {
recomm_prdct_img=view.findViewById(R.id.recomm_prdct_img);
recomm_prdct_itemtitle=view.findViewById(R.id.recomm_prdct_itemtitle);
recomm_prdct_itemdesc=view.findViewById(R.id.recomm_prdct_itemdesc);
}
}
}
HomeActivity.java:
recomm_recycler.setLayoutManager(new LinearLayoutManager(HomeActivity.this,LinearLayout.HORIZONTAL,false));
recomm_recycler.setAdapter(new HomeRecommendedProductsAdapter());
The textview with id "recomm_prdct_itemdesc" cannot have the height set to matchconstraint as it does not have a reference view to match its constraint like the width which can be matched to imageview with id "recomm_prdct_img". It should be set to wrapcontent.

Constraint layout with child constraint layouts not expanding horizontally

I'm trying to build a rectangular view (spanning the width of the screen) which is split horizontally into three blocks, and I am doing so using a constraint layout. The left and right blocks have a specified width, but the centre block should expand to fit the remaining space. Because I require that the left-most block have a different background colour to the parent, I have grouped its children into another constraint layout. I have given the layout XML below:
<?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="100dp"
android:layout_marginTop="8dp"
android:background="#10000000"
xmlns:tools="http://schemas.android.com/tools">
<android.support.constraint.ConstraintLayout
android:id="#+id/abc"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#50000000"
android:layout_marginEnd="8dp"
android:padding="2dp"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/jkl"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/def"
android:gravity="start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/ghi"
android:gravity="start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/def" />
</android.support.constraint.ConstraintLayout>
<!-- This should expand to fit the remainder of the screen width -->
<android.support.constraint.ConstraintLayout
android:id="#+id/jkl"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintEnd_toStartOf="#+id/stu"
app:layout_constraintStart_toEndOf="#+id/abc">
<TextView
android:id="#+id/mno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|start"
android:textColor="#a0000000"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/pqr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|start"
android:textColor="#a0000000"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mno" />
</android.support.constraint.ConstraintLayout>
<ImageButton
android:id="#+id/stu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="#drawable/x"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/jkl"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Unfortunately, the middle block does not expand to fit the remaining width of the screen. Does anyone know how to achieve this? Am I doing anything fundamentally wrong here?
Edit:
Based on Ben P.'s response it may be that the XML above is fine, but the layouts in which this layout is contained are at fault. I have therefore provided them below.
This layout XML is the parent of the XML above:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.Parent">
</android.support.v7.widget.RecyclerView>
This layout XML is the parent of the RecyclerView XML above:
<?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"
tools:context="com.example.MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
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" />
<include layout="#layout/bottom_navigation" />
</android.support.constraint.ConstraintLayout>
Edit 2:
As requested I've provided the complete code base:
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private FragmentManager mFragmentManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, new Foo());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
Foo.java:
public class Foo extends Fragment {
private String[] mDataset;
private OnFragmentInteractionListener mListener;
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
public Foo() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment Foo.
*/
// TODO: Rename and change types and number of parameters
public static Foo newInstance(String param1, String param2) {
Foo fragment = new Foo();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
initDataset();
}
private void initDataset() {
mDataset = new String[1];
mDataset[0] = "Hello World";
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_foo, container, false);
mRecyclerView = view.findViewById(R.id.foo_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new FooAdapter(mDataset);
mRecyclerView.setAdapter(mAdapter);
return view;
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
FooAdapter.java:
public class FooAdapter extends RecyclerView.Adapter<FooAdapter.ViewHolder> {
private String[] mDataset;
public static class ViewHolder extends RecyclerView.ViewHolder {
private TextView mFoofoo;
private TextView mBarbar;
public ViewHolder(View itemView) {
super(itemView);
mFoofoo = itemView.findViewById(R.id.foofoo);
mBarbar = itemView.findViewById(R.id.barbar);
}
public TextView getFoofoo() {
return mFoo;
}
public TextView getBarbar() {
return mBar;
}
}
public FooAdapter(String[] mDataset) {
this.mDataset = mDataset;
}
#Override
public FooAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.bar, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(FooAdapter.ViewHolder holder, int position) {
String text = mDataset[position];
holder.getBarbar().setText(text);
holder.getFoofoo().setText(text);
}
#Override
public int getItemCount() {
return mDataset.length;
}
}
activity_main.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"
tools:context="com.example.MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaff73"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
fragment.xml:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/foo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8df78b"
tools:context="com.example.Foo">
</android.support.v7.widget.RecyclerView>
bar.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"
android:layout_width="match_parent"
android:layout_height="104dp"
android:layout_marginTop="4dp"
android:background="#10000000"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="#+id/backg"
android:background="#50000000"
android:layout_width="104dp"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/foofoo"
android:gravity="start"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/action"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_width="wrap_content"
android:src="#drawable/pic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/barbar"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/barbar"
android:autoSizeMaxTextSize="24sp"
android:autoSizeMinTextSize="14dp"
android:autoSizeStepGranularity="2dp"
android:autoSizeTextType="uniform"
android:background="#ef0505"
android:gravity="top|start"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:textColor="#a0000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#id/action"
app:layout_constraintStart_toEndOf="#id/backg"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Any help is greatly appreciated!
I do not know why this works, but it does.
In bar.xml, replace your outer ConstraintLayout's height with wrap_content (instead of 104dp).
Also in bar.xml, replace your ImageView's height with 104dp (instead of 0dp).
This has the net effect of keeping your layout's design the same... it just has the ConstraintLayout's height defined by the ImageView's height, instead of the other way around.
If I had to guess at why this makes a difference, I'd assume that there's some quirk in the way LinearLayoutManager measures its children, and that when it sees a fixed height it ignores the match_parent width. But that's wild speculation.
Update
Here is a flat ConstraintLayout that does what I believe you want:
<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="100dp">
<ImageView
android:id="#+id/image"
android:layout_width="100dp"
android:layout_height="0dp"
android:background="#33000000"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:id="#+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="#+id/image"
app:layout_constraintRight_toRightOf="#+id/image"
tools:text="line 1"/>
<TextView
android:id="#+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
app:layout_constraintTop_toBottomOf="#+id/text1"
app:layout_constraintLeft_toLeftOf="#+id/image"
app:layout_constraintRight_toRightOf="#+id/image"
tools:text="line 2"/>
<TextView
android:id="#+id/text3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#+id/image"
app:layout_constraintRight_toLeftOf="#+id/button"
tools:text="line 3"/>
<TextView
android:id="#+id/text4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="4dp"
app:layout_constraintTop_toBottomOf="#+id/text3"
app:layout_constraintLeft_toRightOf="#+id/image"
app:layout_constraintRight_toLeftOf="#+id/button"
tools:text="line 4"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="button"/>
</android.support.constraint.ConstraintLayout>
And what it looks like:
Original
This does not strictly answer the question (since as far as I can tell, there is no problem with the posted layout), but...
I see no reason to implement this UI using ConstraintLayout. The benefit of ConstraintLayout is that it allows you to avoid nesting ViewGroups inside your top-level View. But as your ConstraintLayout is written, you're still grouping your TextViews inside a mid-level View.
If you are not taking advantage of ConstraintLayout's ability to do organization without nesting, I think it is a better idea to use a simpler top-level view. Here is your UI reimplemented with LinearLayouts:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="8dp"
android:background="#10000000"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/abc"
android:layout_width="100dp"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#50000000"
android:orientation="vertical">
<TextView
android:id="#+id/def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="18sp"
tools:text="line 1"/>
<TextView
android:id="#+id/ghi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="14sp"
tools:text="line 2"/>
</LinearLayout>
<LinearLayout
android:id="#+id/jkl"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/mno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#a0000000"
android:textSize="14sp"
android:textStyle="bold"
tools:text="line 1"/>
<TextView
android:id="#+id/pqr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#a0000000"
android:textSize="14sp"
tools:text="line 2"/>
</LinearLayout>
<ImageButton
android:id="#+id/stu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:src="#drawable/plus"/>
</LinearLayout>

Categories

Resources