2012-03-30 6 views
0

1つのフレーム内に2つのframeLayoutを挿入できますか? 私はこのコードを試しても動作しません!別のフレームレイアウト内にフレームレイアウトを挿入する

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:baselineAligned="false" 
    android:orientation="horizontal" > 

    <FrameLayout 
     android:id="@+id/titles" 
     android:layout_width="0px" 
     android:layout_height="match_parent" 
     android:layout_weight="1" /> 
    <FrameLayout 
      android:id="@+id/details" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="2" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:baselineAligned="false" 
      android:orientation="horizontal" > 

      <FrameLayout 
       android:id="@+id/details1" 
       android:layout_width="0px" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <FrameLayout 
       android:id="@+id/details2" 
       android:layout_width="0px" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 
     </LinearLayout> 
    </FrameLayout> 


</LinearLayout> 

1つの要素をクリックすると、detail1が印刷されます。私はdetail1が詳細の下で作成されているので、私はそれを見ることができないと思いますか?

助けてもらえますか?

私が欲しいものがあります:あなたはすべてのために幅0PXを持っている場合 enter image description here

enter image description here

答えて

1

が答えです:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    Top-level content view for the layout fragment sample. This version is 
    for display when in landscape: we can fit both titles and dialog. 
--> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:baselineAligned="false" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:baselineAligned="false" 
     android:orientation="horizontal" > 

     <FrameLayout 
      android:id="@+id/titles" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <FrameLayout 
      android:id="@+id/details" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="2" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:baselineAligned="false" 
     android:orientation="horizontal" > 

     <FrameLayout 
      android:id="@+id/titles1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 

     <FrameLayout 
      android:id="@+id/details1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <FrameLayout 
      android:id="@+id/details2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</RelativeLayout> 

私は良い結果:)すべてのボディに おかげです助けて、th anks

0

は、どのようなあなたがして見に行くの?そして、pxを使わないで、dipを使ってください。私はあなたがとにかく

、達成しようとしているかわからない、私は問題はあなたが完全にlayout_weightの使用方法を理解していないことだと思い

+0

これは動作しないことができます。<でframeLayout アンドロイド:ID = "@ + ID /詳細" アンドロイド:layout_width = "match_parent" アンドロイド:layout_heightは= "match_parent"> アンドロイド:layout_width = "match_parent" 作りをすべての画面で私のフレームレイアウト、android:layout_weight = "2"は動作しません –

+0

あなたは何かをスケッチを描いて、私たちがあなたが欲しいものを見てみましょうここに投稿しないでください。 –

+0

私は私の質問に画像に参加しました –

0

[私の答えを削除]。デザイン内の異なるlayout_weightsに接続されているビューのファミリ(親と子)をより正確に把握する必要があります。

どのように動作するのかは完全にはわかりませんが、左側のメニューを常に表示してから、ユーザーが選択した内容に応じて詳細を詳細に表示したいとします。あなたはまた、地図が常に部分的に見えるようにしたいですか?

上記を行うコードを一緒にスローしました。コードを使いこなせば、おそらくそれがどのように動作するのか理解できます。あなたがコードを理解することに問題がある場合、または私があなたが望むものを誤解しているかどうか教えてください。ここで

main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 
    <LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1.0" 
     android:orientation="vertical" 
     android:background="@android:color/white" 
    > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Menu" 
      android:textColor="@android:color/black" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Show Details" 
      android:onClick="showdetails" /> 

    </LinearLayout> 

    <FrameLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="2.0" 
    > 
     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/ic_launcher" /> 

     <LinearLayout 
      android:id="@+id/DetailsLinearLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="gone" 
     > 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_weight="1.0" 
       android:text="Details" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:textColor="@android:color/black" 
       android:background="@android:color/white" /> 

      <!-- This view is only here to prevent textView2 from completly 
       covering the underlying picture --> 
      <View 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1.0" /> 
     </LinearLayout> 

    </FrameLayout> 

</LinearLayout> 

javaの

package com.test.insertframelayoutinsideanotherframelayout; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.LinearLayout; 

public class InsertframelayoutinsideanotherframelayoutActivity extends Activity { 

    LinearLayout detailsLinearLayout; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     detailsLinearLayout = (LinearLayout) findViewById(R.id.DetailsLinearLayout); 
    } 

    public void showdetails(View v){ 
     if (detailsLinearLayout.getVisibility() == View.GONE){ 
      detailsLinearLayout.setVisibility(View.VISIBLE); 
     } 
     else { 
      detailsLinearLayout.setVisibility(View.GONE); 
     } 
    } 
} 
関連する問題