Сделать матрицу пикселей с TextView - PullRequest
1 голос
/ 04 октября 2019

Моя основная идея - создать матрицу пикселей и получить доступ к каждой ячейке в моем коде, чтобы изменить ее цвет. Мне пришла в голову идея использовать Textview из PixelArtist

Я хочу показатьМоя матрица (35 * 10) в части экрана (например, 40% размера экрана) и приложение работают только в ландшафтном режиме. Моя проблема в том, что приложение показывает только одну строку. изображение из симулятора

код mainactivity.xml:

<?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"

    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline_mid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.3" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline_low"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.60" />



    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline_bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="1" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline_top"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0" />

    <LinearLayout
        android:id="@+id/pic_frame_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toTopOf="@+id/guideline_bottom"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline_low">

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />

        <include layout="@layout/paper_line" />



    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

my paperline.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />

    <TextView style="@style/Pixel" />




</LinearLayout>

и стиль пикселей

    <style name="Pixel">
        <item name="android:layout_width">25dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:layout_height">25dp</item>
        <item name="android:layout_marginTop">1dp</item>
        <item name="android:layout_marginLeft">1dp</item>
               <item name="background">@color/white</item>
    </style>

спасибо

1 Ответ

0 голосов
/ 04 октября 2019

Проблема в том, что my paperline.xml высота установлена ​​на match_parent. Измените это значение на wrap_content

. Также, если вы не планируете помещать в них какой-либо текст, вы, вероятно, можете просто использовать Viewиз TextView


Кроме того, если вы не возражаете против изменения размера каждого блока и хотите добавить все в любой вид, чем вы можете изменить следующее:

Сделайте свойпиксель выглядит следующим образом:

    <style name="Pixel">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_marginTop">1dp</item>
        <item name="android:layout_marginLeft">1dp</item>
        <item name="background">@color/white</item>
    </style>

И верхняя часть my paperline.xml выглядит следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp">

Путем установки ширины или высоты вида внутри от LinearLayout до 0dpи предоставляя вес, вид будет динамически вычислять ширину / высоту на основе веса. Если все веса одинаковы, то все они будут равномерно распределены.

...