вставить макет кадра внутри другого макета кадра - PullRequest
0 голосов
/ 30 марта 2012

Могу ли я вставить два frameLayout в один 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>

Когда я нажимаю на один элемент, я хочу, чтобы detail1 был напечатан.Я думаю, detail1 был создан под деталями, поэтому я не могу его увидеть?

Может ли кто-нибудь помочь, пожалуйста?

Есть то, что я хочу: enter image description here

enter image description here

Ответы [ 3 ]

1 голос
/ 31 марта 2012

Вот ответ:

<?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>

Я получил хороший результат :) спасибо за помощь каждому телу, спасибо

0 голосов
/ 31 марта 2012

Я думаю, что проблема в том, что вы не совсем поняли, как использовать layout_weight. И вы должны лучше отслеживать, какая семья (родительская и дочерняя) представлений связана с различными 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);
        }
    }
}
0 голосов
/ 30 марта 2012

если у вас ширина 0px для всех, что вы тогда увидите? И не используйте px, используйте dip. Во всяком случае, я не знаю, чего вы пытаетесь достичь

[удалил мой ответ]

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...