Авторазмер всех текстовых представлений в GridLayout до размера самого маленького в группе - PullRequest
0 голосов
/ 17 апреля 2019

Я пытаюсь добиться того, чтобы в группе слов разной длины (например, Apple, Airplane, Procrastinate, ...) наименьший размер текста автоматически устанавливался во всех словах.

Сейчас я использую функцию autoSizeTextType, однако это приводит к словам разной длины, которые не радуют глаз.

XML-код

<android.support.v7.widget.GridLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
    app:alignmentMode="alignMargins"
    app:columnCount="2"
    app:autoSizeTextType="uniform"
    app:rowCount="3">

    <android.support.v7.widget.CardView
        android:id="@+id/cardOne"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        app:layout_rowWeight="1"
        app:layout_columnWeight="1"
        android:foreground="?android:attr/selectableItemBackground"
        app:cardBackgroundColor="#69b4c9"
        app:cardCornerRadius="30dp"
        app:cardElevation="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="5dp">

            <TextView
                android:id="@+id/wordOne"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:paddingRight="20dp"
                android:paddingLeft="20dp"
                android:textStyle="bold"
                android:layout_weight="1"
                app:autoSizeTextType="uniform"
                android:textColor="@android:color/white"
                android:textAlignment="center"/>
        </LinearLayout>
    </android.support.v7.widget.CardView>


    <android.support.v7.widget.CardView
        android:id="@+id/cardTwo"
        android:layout_height="0dp"
        android:layout_width="0dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        app:layout_rowWeight="1"
        app:layout_columnWeight="1"
        android:foreground="?android:attr/selectableItemBackground"
        app:cardBackgroundColor="#69b4c9"
        app:cardCornerRadius="30dp"
        app:cardElevation="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="5dp">

            <TextView
                android:id="@+id/wordTwo"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:paddingRight="20dp"
                android:paddingLeft="20dp"
                android:textStyle="bold"
                android:layout_weight="1"
                app:autoSizeTextType="uniform"
                android:textColor="@android:color/white"
                android:textAlignment="center"/>
        </LinearLayout>
    </android.support.v7.widget.CardView>

    (REPEATS THE CARD VIEW 8 MORE TIMES)

</android.support.v7.widget.GridLayout>

JAVA CODE (пропущенные переменные и методы, не относящиеся к вопросу)

public class VentanaLevelFive extends AppCompatActivity {

private TextView text, wordOne, wordTwo;
private CardView cardOne, cardTwo;
private ArrayList<String> wordList = new ArrayList<>();
private ArrayList<CharSequence> selectedWord = new ArrayList<>();
private Handler handler = new Handler();
private static final int DELAY = 2000;
private int counter, i, userId;
private Button startBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ventana_level_five);
    getSupportActionBar().hide();

    text = findViewById(R.id.text);
    startBtn = findViewById(R.id.startBtn);

    //words
    wordOne = findViewById(R.id.wordOne);
    wordTwo = findViewById(R.id.wordTwo);

    //cards
    cardOne = findViewById(R.id.cardOne);
    cardTwo = findViewById(R.id.cardTwo);

    //getting language of phone
    String language = Locale.getDefault().getLanguage();

    //reading words from file
    BufferedReader reader;
    try {
        InputStream is = getAssets().open("wordsDificil-"+language+".txt");
        reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
        String line = reader.readLine();
        while (line != null) {
            line = reader.readLine();
            wordList.add(line);
        }
        reader.close();
        this.setWords();
    } catch (IOException e) {
        e.printStackTrace();
    }

    startBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startBtn.setEnabled(false);
            VentanaLevelFive.this.enableButtons();
            counter = 0;
            i = 0;
            mRunnable.run();
        }
    });
    cardOne.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (wordOne.getText() == text.getText()) {
                cardOne.setBackgroundResource(R.drawable.buttonbackgr_correct);
                counter++;
                VentanaLevelFive.this.disableButtons();
            }else{
                cardOne.setBackgroundResource(R.drawable.buttonbackgr_wrong);
                VentanaLevelFive.this.disableButtons();
            }
        }
    });
    cardTwo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (wordTwo.getText() == text.getText()) {
                cardTwo.setBackgroundResource(R.drawable.buttonbackgr_correct);
                counter++;
                VentanaLevelFive.this.disableButtons();
            }else{
                cardTwo.setBackgroundResource(R.drawable.buttonbackgr_wrong);
                VentanaLevelFive.this.disableButtons();
            }
        }
    });  

(я не могу публиковать изображения, так что это прямые ссылки на них)

Вот что у меня сейчас:

до

И это то, чего я хочу достичь

ПОСЛЕ

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...