الروبوت linearlayout.
-
12-09-2019 - |
سؤال
أريد أن أضع نصين نصي على اليسار، وزر واحد إلى اليمين داخل تخطيط خطي، هل هذا ممكن؟ ما يلي هو الرمز الخاص بي حيث اضطررت إلى تشغيل الأرجق من الزر، وهذا غير مرن. هل من الممكن تخطيط الأطفال الذين يتدفقون في اتجاهات مختلفة؟
<LinearLayout
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="100px"
>
<TextView
android:id="@+id/tc_buttom_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time elapsed"
>
</TextView>
<TextView
android:id="@+id/tc_buttom_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00 00"
>
</TextView>
<Button
android:id="@+id/tc2_home"
android:layout_width="70px"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:layout_marginRight="10px"
android:text="Home"
android:layout_weight="0.5"
>
</Button>
</LinearLayout>
المحلول
أريد أن أضع نصين نصي على اليسار، وزر واحد إلى اليمين داخل تخطيط خطي، هل هذا ممكن؟
ليس مع واحد LinearLayout
. وبعد إما تحتاج اثنين LinearLayout
S (واحد لعمود اثنين TextView
S على اليسار)، أو واحد relativelayout.
هل من الممكن تخطيط الأطفال الذين يتدفقون في اتجاهات مختلفة؟
إذا كنت من خلال "اتجاهات مختلفة" تقصد كلاهما رأسيا وأفقيا في وقت واحد، واحدة LinearLayout
يمكن أن تذهب فقط في اتجاه واحد. إما استخدام المتداخل LinearLayout
S أو أ RelativeLayout
.
نصائح أخرى
إما استخدام اثنين من التصميم الخطي (واحد مع اتجاه أفقي وغيرها مع الاتجاه الرأسي) أو استخدام التصميم النسبي. التصميم النسبي أقوى من خطي وسهل الاستخدام
تحتاج إلى استخدام تخطيط الجدول. انظر إلى مثال تخطيط الطاولة في Demos API.
Table layout - with 'stretch columns' = 1,
-- Table row - with width = fill_parent,
-- Text View,
-- Text View,
-- Button,
سيحتفظ بهذا الزر الأيمن إلى الحافة اليمنى للشاشة
linearlayout. لديه orientation
ينسب. جرب شيئا مثل هذا:
<LinearLayout
android:id="@+id/widget43"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="100px"
>
استخدام التالية:
<LinearLayout
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="100px"
android:layout_margin="16dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tc_buttom_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time elapsed"></TextView>
<TextView
android:id="@+id/tc_buttom_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="00:00:00 00"></TextView>
</LinearLayout>
<Button
android:id="@+id/tc2_home"
android:layout_width="70px"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:layout_marginRight="10px"
android:layout_weight="0.5"
android:text="Home"></Button>
</LinearLayout>
لمزيد من تعليمات Android تخطيطات ومثال: http://www.viralandroidroid.com/2015/11/Android-layouts.html.
يمكنني استخدام اثنين من linearlayout مثل هذا:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:baselineAligned="false"
android:orientation="vertical"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/fullscreen_choose_controls"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/fullscreen_esop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/vs_esop"
android:textAllCaps="false"
android:textColor="@android:color/holo_blue_dark"
android:textSize="50sp"
android:textStyle="bold" />
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:ellipsize="end"
android:gravity="center"
android:text="@string/dummy_button"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/fullscreen_android"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/vs_android"
android:textAllCaps="false"
android:textColor="@android:color/holo_blue_dark"
android:textSize="50sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/fullscreen_make_your_choice"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/vs_make_your_choice"
android:textColor="@android:color/holo_red_dark"
android:textSize="50sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
</FrameLayout>