Whatsup - לינוקס, תוכנה חופשית וקוד פתוח בעברית

תיכנות בלינוקס - בעית עריכת layout עם android sutdio?

Anonymous - 02/04/2017 - 16:03
נושא ההודעה: בעית עריכת layout עם android sutdio?
אני מתחיל לערוך layout עם android studio אבל נתקל בבעיה מוזרה
ערכתי כמה buttons וגם textviews וסדרתי אותם יפה על מסך המחשב, אבל על האמולטור (או על המכשיר עם adb), כל buttons ,textviews מופיעים בבלגן אחד על השני בפינה השמאלית של המסך. אם אני לוחץ קליק ימני על button מסוים ובחירת אחת או שתי האפשרויות: center horizontally, center vertically, אז זה יוצא בסדר גם במכשיר אבל זה יוצר צמידות לכפתורים אחרים ומוריד מגמישות ונוחות העריכה. אין דרך לערוך פשוט את הכפתורים ושיצאו אותו דבר גם על המכשיר? מניח שיש דרך קלה יותר. עברתי על המדריכים שנמצאים באתר הרשמי ולא מצאתי התיחסות לבעיה הזו. אולי זה קשור למושג ConstraintLayout שאשמח להסבר עליו, שמופיע בקישור הבא:
https://developer.android.com/studio/write/layout-editor.html#intro
המלצה על מדריך עריכה טוב תתקבל בברכה
elcuco - 02/04/2017 - 22:12
נושא ההודעה: Re: בעית עריכת layout עם android sutdio?
Anonymous :
אני מתחיל לערוך layout עם android studio אבל נתקל בבעיה מוזרה
ערכתי כמה buttons וגם textviews וסדרתי אותם יפה על מסך המחשב, אבל על האמולטור (או על המכשיר עם adb), כל buttons ,textviews מופיעים בבלגן אחד על השני בפינה השמאלית של המסך. אם אני לוחץ קליק ימני על button מסוים ובחירת אחת או שתי האפשרויות: center horizontally, center vertically, אז זה יוצא בסדר גם במכשיר אבל זה יוצר צמידות לכפתורים אחרים ומוריד מגמישות ונוחות העריכה. אין דרך לערוך פשוט את הכפתורים ושיצאו אותו דבר גם על המכשיר? מניח שיש דרך קלה יותר. עברתי על המדריכים שנמצאים באתר הרשמי ולא מצאתי התיחסות לבעיה הזו. אולי זה קשור למושג ConstraintLayout שאשמח להסבר עליו, שמופיע בקישור הבא:
https://developer.android.com/studio/write/layout-editor.html#intro
המלצה על מדריך עריכה טוב תתקבל בברכה


1- כל הזין. זה מה יש ועם זה צריך לנצח. אין קליע כסף.
2- תעלה את ה־XML שלך איפשהו וננסה לעזור לך.
Anonymous - 02/04/2017 - 23:02
נושא ההודעה:
יש מצב לנושא שיחה שונה מ android sutdio ?
Anonymous - 02/04/2017 - 23:27
נושא ההודעה:
המטרה הפשוטה היא שהעריכה תצא במכשיר אותו דבר כמו במחשב. אם אני עורך כפתורים על ידי גרירה מ pallet אז הם מופיעים יפה על צג המחשב, אבל על המכשיר הם מופיעים כולם ביחד בפינה השמאלית עליונה. הבעיה נפתרה לכאורה על ידי קליק ימני על הכפתורים ו center vertically. כנראה שאני עושה משהו לא נכון - אמור להיות פתרון יותר טוב? הנה דוגמת 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.mgarch.mathgamechapter2.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.509"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.512"
        android:id="@+id/textView2" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="30sp"
        app:layout_constraintBottom_toTopOf="@+id/imageView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="My Math Game" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:srcCompat="@mipmap/ic_launcher" />

    <Button
        android:id="@+id/buttonPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Play"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="High Scores"
        app:layout_constraintBottom_toTopOf="@+id/button3"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonPlay" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Quit"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

</android.support.constraint.ConstraintLayout>

Anonymous - 02/04/2017 - 23:31
נושא ההודעה:
תיקון: ב XML הזה בחרתי ב center horizontally
אם אתה רוצה לראות XML עם הכפתורים מבולגנים (ללא שימוש ב center) אז אני איצר אחד
elcuco - 03/04/2017 - 15:25
נושא ההודעה:
נסה להשתמש ב-RelativeLayout במקום ב-ConstraintLayout. אני אישית לא הסתדרתי איתו.
Anonymous - 03/04/2017 - 22:26
נושא ההודעה:
שיניתי ב XML ל RelativeLayout - גם כאן יש קשרים בין הכפתורים השונים ואצטרך ללמוד את זה קצת, אבל הרבה יותר נוח. ברירית המחדל היא ConstraintLayout - אולי יש לה יתרונות במקרים מסוימים אבל לא כל כך מכיר אותה וגרמה לי לבלגן. ראיתי שיש גם LinearLayout ומצאתי איזה מדריך:
https://www.tutorialspoint.com/android/index.htm

תודה
כל הזמנים הם GMT + 2 שעות