2

次のxmlでDrawerLayoutを使用しています:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" >
  <android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  <FrameLayout
    android:id="@+id/detail_container"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="end" >
  </FrameLayout>
  <View
    android:layout_width="140dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#0000ff" />
</android.support.v4.widget.DrawerLayout>

アイデアは、OpenGL と両側の引き出しであるメイン ビューを持っているということです。「detail_container」には、次の onCreate() (Scala の場合) のフラグメントがプログラムによって取り込まれます。

override def onCreate(bundle: Bundle) {
    super.onCreate(bundle)
    setContentView(R.layout.main)//important: this is how you specify the xml file that defines the layout for this activity

    def setupActionBar(){
      val bar = getActionBar
      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
      bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE)
      val mapTab = bar.newTab().setText("Map")
      val detailTab = bar.newTab().setText("Detail")
      mapTab.setTabListener(new MyTabsListener)
      detailTab.setTabListener(new MyTabsListener)
      bar.addTab(mapTab)
      bar.addTab(detailTab)
      bar.show()
    }

    def setupOglRenderer(){
      findViewById(R.id.glsurfaceview) match {
        case v: GLSurfaceView => {
          val renderer = new OpenGlRenderer(this, R.drawable.aqua_oval)
          v.setRenderer(renderer)
        }
        case _ =>
      }
    }

    def setupDetailFragment(){
      if(findViewById(R.id.detail_container) != null){
        if(bundle == null){//don't do anything if restoring
          val detailFrag = new DetailFrag
          detailFrag.setArguments(getIntent.getExtras)
          getSupportFragmentManager.beginTransaction().add(R.id.detail_container, detailFrag).commit()
        }
      }
    }

    setupActionBar()
    setupOglRenderer()
    setupDetailFragment()
  }

詳細フラグメント クラスには、次の onCreateView があります。

override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = {
  val v = inflater.inflate(R.layout.detail_fragment, container, false)
  v.setBackgroundColor(0x557B68EE)
  //v.setBackgroundResource(R.drawable.aqua_sqaure)
  v.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN)

  v
}

これはすべて正常に機能しますが、背景として 9 パッチを設定しようとすると、UI コンポーネントが表示されません。onCreateView と detail_container の xml で背景のドローアブルを次のように設定しようとしました。

android:background="@drawable/aqua_sqaure"

どちらの場合も、背景画像しか表示されません。背景を削除すると、UI コンポーネントが表示されます。背景色をうまく設定できます。画像だけが表示され、UI が非表示または上書きされます。

私は何を間違っていますか?

どんな助けでも大歓迎です。ありがとう

更新: これは、私が使用していた 9 パッチに関連しているようです。他の 9 パッチ イメージを使用すると、コードは期待どおりに動作します。

4

0 に答える 0