PDA

View Full Version : اشکال کد لی آوت



بیتا حکمت
شنبه 04 مهر 1394, 21:20 عصر
سلام ، این کد بدون مشکل اجرا میشه (رندر میشه )




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

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" android:id="@+id/btn21"/>

</LinearLayout>



اما من میخوام باتن ها به صورت عمودی زیر هم قرار بگیرن ، مثلا اول دکمه 1 باشه با فاصله دکمه دوم باشه و با فاصله دیگری دکمه سوم و ..
به همین خاطر میخوام از کد پایین استفاده کنم ولی خطا صادر میشه .





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="5">

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" android:id="@+id/btn21"/>

</LinearLayout>

Mostefea1372
شنبه 04 مهر 1394, 23:15 عصر
این هم کدی کی می خواستی ... پیشنهاد می کنم یکم در مورد طراحی رابط در xml تحقیق کن

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

<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="1" />

<Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="2" />

<Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="3" android:id="@+id/btn21"/>

</LinearLayout>

بیتا حکمت
یک شنبه 05 مهر 1394, 08:11 صبح
این هم کدی کی می خواستی ... پیشنهاد می کنم یکم در مورد طراحی رابط در xml تحقیق کن

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

<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="1" />

<Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="2" />

<Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.33"
android:text="3" android:id="@+id/btn21"/>

</LinearLayout>

ممنونم ، حتما" در موردش مطالعه می کنم ، فقط یه سوال اون کدی که تو پست اول گذاشتم تو همین سایت برنامه نویس بود و نویسنده کد گفته بودش که
با این کد مشکل رزولیشون و سایز تو گوشی های مختلف پیش نمیاد ، کدی که شما هم گذاشتن اینجوره ؟!
و اینکه من اصلا متوجه نشدم اشکال کد پست 1 چی بود که اجرا نمی شد

Mostefea1372
سه شنبه 07 مهر 1394, 01:33 صبح
سلام

برای این که دکمه های یا اشیا داخل لیوت هم زمان با سایز صفحه تغییر بکنن میشه از چند روش استفاده کرد

مثلا دادن حجم در سورس xml

یا دادن درصد به اندازه طول و عرض صفحه نمایش (که این بیشترین کاربرد رو در j2me داشت) و توی اندروید هم قابل استفاده هستش

و .......
کد بالا با استفادهاز حجم اندازه ها رو تنظیم کرده بود که اندازه رو به صورت درصدی میدن نه شماره دکمه
شما در کد بالا از حجم استفاده کردید ولی به جای ارتفاع عرض رو صفر داده بودید

مثلا اگه 4 دکمه دارید حجم رو به صورت 0.25 و یا اگر 3 دکمه دارید حجم رو به صورت 0.33 میدید که دکمه ها هم اندازه حجم بگیرند