0

I have the following layout:

Each of the Pokemon Team rows has a fixed size of 100dp :

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pokemonTeambuilderContainer"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <TextView
        android:id="@+id/pokemonTeambuilderTitleTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/untitled"
        android:textSize="16sp"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/pokemonTeambuilderSpritesLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal" />

</LinearLayout>
</androidx.cardview.widget.CardView>

enter image description here

The Pokemon inside each row are image view created in this adapter :

  @Override
public void onBindViewHolder(ViewHolder holder, int position) {
    PokemonTeam pokemonTeam = mData.get(position);

    for (Pokemon pokemon : pokemonTeam.getPokemonList()) {
        CircularImageView ivPokemonSprite = new CircularImageView(mContext);
        int color = PokemonUtils.getDominantColorFromPokemon(pokemon.get_id(), mContext);
        ivPokemonSprite.setBorderColor(color);
        ivPokemonSprite.setBorderWidth(4);

        ivPokemonSprite.setCircleColor(PokemonUtils.lighterColor(color, DARK_FACTOR));
        Picasso.get().load(PokemonUtils.getPokemonSugimoriImageById(pokemon.get_id(), mContext)).fit().centerCrop().into(ivPokemonSprite);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
        layoutParams.setMargins(3, 10, 3, 10);
        ivPokemonSprite.setLayoutParams(layoutParams);
        holder.teamSpritesLinearLayout.addView(ivPokemonSprite);
    }

    String pokemonTeamName = pokemonTeam.getName();
    if (pokemonTeamName != null && !pokemonTeamName.isEmpty()) {
        holder.teamTitleTextView.setText(pokemonTeam.getName());
    }

}

My problem is when I rotate the device :

enter image description here

I would like to have at least 200dp of height in order to make each row bigger (otherwise I think that in devices like Tablet it will look very small), like this :

enter image description here

Nexussim Lements
  • 535
  • 1
  • 15
  • 47
  • 2
    You have to create 2 layout folder inside your project->res folder. 1- layout 2- layout-large. In both layout id or views must be same. – Sanwal Singh Aug 10 '20 at 09:27

1 Answers1

1

you can have alternative layouts for different devices, I think that's the most reliable way https://developer.android.com/guide/practices/screens_support

You can also check the orientation and set up the height accordingly https://stackoverflow.com/a/2799001/12506486

Stachu
  • 1,614
  • 1
  • 5
  • 17