Вам нужно написать свой Layout, наследуясь от ViewGroup. Какие методы и зачем вам нужно переопределить?
Ответы на вопрос:
Как создать свой Layout с элементами (LinearLayout,Spinner,View и т.п.) внутри так, чтобы управлять их расположением и анимацией?
main_activity.xml:
<LinearLayout
android:id = "@+id/window_1"
android:layout_width="200dp"
android:layout_height="100dp"
android:orientation="vertical">
<Spinner
android:id="@+id/WindowSpinner_1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<FrameLayout
android:id="@+id/container_1"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id = "@+id/window_2"
android:layout_width="200dp"
android:layout_height="100dp"
android:orientation="vertical">
<Spinner
android:id="@+id/WindowSpinner_2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<FrameLayout
android:id="@+id/container_2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id = "@+id/window_3"
android:layout_width="200dp"
android:layout_height="100dp"
android:orientation="vertical">
<Spinner
android:id="@+id/WindowSpinner_3"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<FrameLayout
android:id="@+id/container_3"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id = "@+id/window_4"
android:layout_width="200dp"
android:layout_height="100dp"
android:orientation="vertical">
<Spinner
android:id="@+id/WindowSpinner_4"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<FrameLayout
android:id="@+id/container_4"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</com.android.prog.CustomLayout>
класс CustomLayout.java:
public class CustomLayout extends LinearLayout {
public CustomLayout(Context context) {
super(context);
}
public CustomLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void doSomefing{//Задаём действия с элементами внутри CustomLayout
}
}
Объяснение:
Популярно: Информатика
-
Оленька09008.02.2020 11:15
-
kirra00787p07znc29.01.2022 12:41
-
marina992622.12.2021 10:31
-
kira31004.10.2020 03:20
-
danilejik07.08.2022 12:11
-
SashaLaik07.01.2021 15:23
-
3xoTualetnogo6a4ka22.11.2021 02:08
-
pycya200602.03.2023 05:31
-
стрелыамура207.06.2021 16:55
-
aniavetisa26.05.2022 20:58