3

メイン レイアウト センター画面の上に画像のみを表示するビューを膨張させたいのですが、これまでのところ、膨張したビューをメイン レイアウトの最初の子として追加することしかできません。イメージビューを他のビューの上に表示し、画面の中央に表示するにはどうすればよいですか?

LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = inflater.inflate(R.layout.image_preview,(ViewGroup)findViewById(R.id.previewHolder));
        ((LinearLayout) (LinearLayout)findViewById(R.id.fullScreen)).addView(layout);//add inflated to main view

メインレイアウト

<LinearLayout 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:focusable="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
 >

<LinearLayout
    android:id="@+id/fullScreen"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</LinearLayout>

<TableLayout
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:focusableInTouchMode="true"
    android:stretchColumns="*" >
    ........................
   </TableLayout>
   </LinearLayout>

アクティビティ

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_testing_cam);
            badge.setOnClickListener(btnListener);
          }
  private OnClickListener btnListener = new OnClickListener() { 

         @Override
       public void onClick(View v) {
           //SELECTS BUTTON ACTIONS
        switch(v.getId()){

            case R.id.status:
                finish();
                break;
            default:
                previewImages(v.getId());
                break;
        }
    }
}; 
            //CARRY OUT IMAGE FUNCTIONS
public void previewImages(int index){
    try{

        LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = inflater.inflate(R.layout.image_preview,(ViewGroup)findViewById(R.id.previewHolder));
        ((LinearLayout) (LinearLayout)findViewById(R.id.fullScreen)).addView(layout);



    ImageView iv = (ImageView)findViewById(R.id.previewImage);
    BitmapDrawable drawable = (BitmapDrawable) ((ImageView) showCase.getChildAt(index)).getDrawable();
    Bitmap bitmap = drawable.getBitmap();
    iv.setImageBitmap(bitmap);
    ((LinearLayout) (LinearLayout)findViewById(R.id.fullScreen)).bringToFront();
    }catch(Exception e){ Log.i("ERROR FLATE", e.toString()); }
    return;
}

膨張しているビュー

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/previewImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"/>

4

1 に答える 1

1

フルスクリーンとルートの上にプレビューを追加する場合は、親レイアウトを変更する必要があります。 LinearLayoutその子を垂直に配置しますが、この場合は代わりに aFrameLayoutまたは aを使用する必要がありRelativeLayoutます。このようなもの:

<RelativeLayout 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:focusable="true">

  <!-- your previous content -->
  <LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
      android:id="@+id/fullScreen"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >
    </LinearLayout>

    <TableLayout
      android:id="@+id/root"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      android:focusableInTouchMode="true"
      android:stretchColumns="*" >
      ........................
    </TableLayout>

  </LinearLayout>

  <!-- your preview -->
  <ImageView
    android:id="@+id/preview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="gone"/>

</RelativeLayout>

クリック時に行う必要があるのは、の可視性を変更し、preview ImageViewそれvisibleに応じてソースを設定することだけです。

于 2013-04-20T21:31:59.487 に答える