ScrollView에서 ImageView 위에 버튼을 동적으로 추가하는 방법은 무엇입니까? 기계적 인조 인간. 자 마린

미스터 블 램버

axml 파일이 있습니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mylinearlayout"
android:orientation="vertical"
android:configChanges="orientation|keyboardHidden"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
    android:id="@+id/surfaceView"
    android:layout_height="1dip"
    android:layout_width="1dip" />
<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView1">
    <LinearLayout
        android:id="@+id/filesScrollerLayout"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</ScrollView>
<VideoView
    android:layout_width="1dip"
    android:layout_height="1dip"
    android:id="@+id/videoView1" />

내 응용 프로그램은 사진과 비디오를 가져와 LinearLayout에 넣습니다.

비디오를 추가 할 때 ImageView를 동적으로 만들고이 ImageView에 비디오의 첫 번째 프레임을 넣고 LinearLayout에 추가합니다.

private void addBitmapToLayout(Bitmap bitmap)
{
    ImageView iv = new ImageView(this);
    iv.SetImageBitmap(bitmap);
    linearlayout.AddView(iv);
}

비디오를 시작하기 위해 LinearLayuot의이 ImageView 위에 버튼을 동적으로 배치하려면 어떻게해야합니까? 이렇게 감사합니다.

NSimon

대신 추가하는 ImageView당신에게를 LinearLayout당신이 당신이 볼 수있는 곳, 사용자 정의 레이아웃을 추가 ImageView뿐만 아니라 Button상단에

목록의 각 항목에 대한 레이아웃을 정의하십시오.

<RelativeLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<ImageView
  android:id="@+id/imageView"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<Button
  android:id="@+id/button"
  android:layout_centerInParent="true"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
</RelativeLayout>

이제 함수는 다음과 같습니다.

private void addBitmapToLayout(Bitmap bitmap) {
  LayoutInflater inflater = LayoutInflater.from(context);
  RelativeLayout layout = inflater.inflate(R.layout.list_item, null, false);
  ImageView iv = (ImageView) layout.findViewById(R.id.imageView);
  iv.SetImageBitmap(bitmap);

  //Add click listener to your Button etc...
  Button button = (Button) layout.findViewById(R.id.button);

  linearlayout.AddView(layout);
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관