Reputation: 3273
Can i insert two frameLayout inside one frameLayout? I tried this code and it doesn't work!!!
<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>
When i click on one element i want detail1 to be printed. I guess the detail1 has been created under details so i can't see it?
Can any one help please?
There is what i want:
Upvotes: 0
Views: 9661
Reputation: 5457
if you have width 0px for all, what are you going to see then? And don't use px, use dip. I don't know what you are trying to achieve, anyway
[deleted my answer]
Upvotes: 0
Reputation: 3273
Here is the answer:
<?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>
I got the good result :) thanks to every body help, thanks
Upvotes: 1
Reputation: 4180
I think that the problem is that you have not completely understood how to use layout_weight. And that you must keep better track of which family (parent and children) of views that are connected to different layout_weights in your design.
I am not completely sure how things are supposed to work but I assume that you want the left menu to be visible all the time and then have more details displayed dynamically depending on what the user chooses. You also want the map to be partly visible all the time?
Have thrown together some code that does the above. Play around with the code and you will probably be able to understand how it works. Let me know if you have problems understanding the code or if I have misunderstood what you want.
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);
}
}
}
Upvotes: 0