اذهب إلى المحتوى
  • 0

كيف أتحكم في موضع زر على Android؟

Simoh

السؤال

Recommended Posts

  • 1

للتحكم في موضع الزر "Button" في تطبيق اندرويد، ما عليك إلا تفقد ملف xml الخاص بـ Layout المتعلق بمظهر التطبيق.

مثلا في هذا المثال:

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

    <Button 
    android:layout_centerInParent="true" 
    android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</RelativeLayout>

حيث ستلاحظ وجود المقطع :

android:layout_centerInParent="true"

مما سيجعل الزر يأتي وسط  RelativeLayout المُتضمنة لها.

أيضا لجعل الزر أقل من الوسط بقليل، بالطريقة التالية:

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


    <TextView  android:layout_centerInParent="true" android:layout_width="wrap_content" android:id="@+id/textView1" 
     android:layout_height="wrap_content" android:text=" " ></TextView>
    <Button 
     android:layout_marginTop="5dip"
     android:layout_centerHorizontal="true"
    android:text="Button" android:layout_below="@id/textView1" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</RelativeLayout>

يمكنك تغيير الكود :

android:layout_marginTop="5dip"

للحصول على الشكل المُراد الحصول عليه، فقط غيّر في القيمة للحصول على ذلك.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...