それはアンドロイドで別の上で1つのビューを配置することは可能ですか?

StackOverflow https://stackoverflow.com/questions/3821684

質問

私たちは、別の大きなビューの上に小さなビューを配置することはできますか?例えば、私は、バックグラウンドでファイルを再生しているVideoViewを持っています。この上で、中間のどこか/コーナーでは、私は別のImageViewのを配置します。

しかし、リニア/相対レイアウトでは、ビューは、別の、または互いに対して前後して配置することができ、そしてAbsoluteLayoutのに対して勧められます。だから私は何をしますか?

役に立ちましたか?

解決

FrameLayoutsあなたは下記1の上に各ビューを重ねてみましょう。また、これはRelativeLayoutで達成することができます。

他のヒント

FrameLayoutは、最も単純なViewGroupであり、それらは、レイアウトXML(またはプログラム添加)で定義されている順序でViewsスタック。最初は低くなり、最後は一番上になります。

はここでは、2つViewsを積層し、より良い点を説明するためにオフセットされている例であります

 ここに画像の説明を入力

ここでは2つの重複TextViewボックスで実際のレイアウトXMLがあります。 2つのボックスのオフセットandroid:layout_gravity各ボックス内のテキスト自体をセンタリングするために使用されている間android:gravityを使用して行われます。

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

    <TextView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="top|left"
        android:background="@android:color/holo_blue_light"
        android:gravity="center"
        android:text="First is below"/>

    <TextView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="bottom|right"
        android:background="@android:color/holo_green_light"
        android:gravity="center"
        android:text=" Last is on top"/>

</FrameLayout>

ちょうどあなたがButtonViewの上、次にこれを使用する上でビューを配置する場合場合。 ボタンの上に配置する必要があるビューのandroid:elevation="7dp"

また、 ConstraintLayout に新しいレイアウトを使用することによってそれを行うことができますグーグルによって導入されます。

  

ConstraintLayoutあなたはフラットビュー階層(なしネストされたビュー・グループ)と大規模で複雑なレイアウトを作成することができます。

 <?xml version="1.0" encoding="utf-8"?>
  <android.support.constraint.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/container"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:layout_weight="4"
  tools:context="com.edalat.example.MainActivity">
  <VideoView
    android:id="@+id/videoView"
    android:layout_width="283dp"
    android:layout_height="349dp"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginBottom="24dp"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="24dp"
    android:layout_marginRight="24dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginLeft="24dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintHorizontal_bias="0.509"/>
  <ImageView
     android:id="@+id/imageView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     app:srcCompat="@mipmap/ic_launcher"
     app:layout_constraintTop_toTopOf="parent"
     android:layout_marginTop="24dp"
     app:layout_constraintBottom_toBottomOf="parent"
     android:layout_marginBottom="24dp"
     android:layout_marginLeft="24dp"
     app:layout_constraintLeft_toLeftOf="parent"
     android:layout_marginRight="24dp"
     app:layout_constraintRight_toRightOf="parent"/>
   </android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/dp_20"
    android:background="@color/yellow"
    >
        <VideoView
            android:id="@+id/videoview"
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:layout_height="300dp"
            android:contentDescription="@string/app_name"
             />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/camera"
            android:layout_margin="30dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:id="@+id/imageView" />

</RelativeLayout>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top