Есть ответ 👍

Вам нужно написать свой Layout, наследуясь от ViewGroup. Какие методы и зачем вам нужно переопределить?​

160
352
Посмотреть ответы 2

Ответы на вопрос:


Как создать свой 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

}

}

Объяснение:


не запланированное и спонтанные мероприятие

Популярно: Информатика