开发者

How to stack diffrent layout objects, over each other?

开发者 https://www.devze.com 2023-04-01 16:05 出处:网络
Hello Guys and probably some Girls, is it possible to stack Layout Objects. So that one Object is over the other one?

Hello Guys and probably some Girls, is it possible to stack Layout Objects. So that one Object is over the other one? My Problem is this, i've got a tabhost and under the tabhost i've got a tablerow with a textview in it.

I made the tabhost tabs invisible,开发者_运维百科 but it hiddes my tablrow with the textview in it,how can i bring it infront?

Here is the Layout.xml

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



 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1">
    <RelativeLayout
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       >
       <FrameLayout
           android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:layout_weight="1" />
       <TabWidget
           android:id="@android:id/tabs"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_alignBottom = "@android:id/tabcontent" 
           android:visibility="invisible"/>

       <TableRow 
            android:id="@+id/ADFilterOverview" 
            android:layout_height="wrap_content" 
            android:onClick="onClickADConfig" 
            android:layout_alignParentBottom="true" 
            android:layout_alignParentLeft="true" 
            android:layout_alignTop="@android:id/tabs" 
            android:layout_width="match_parent">

           <TextView 
                android:text="@string/newadfilter" 
                style="@style/NormalFont" 
                android:layout_gravity="bottom|left">
           </TextView>
       </TableRow>
    </RelativeLayout>
</TabHost>

Thx in Advance

Best Regards safari

Some more information, for better understanding:

Afterwards my code of my Activity looks something like this:

package de.retowaelchli.filterit;

    import android.app.TabActivity;
    import android.os.Bundle;
    import android.widget.TabHost;
    import android.content.Intent;

    public class StatsActivity extends TabActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.stats);
            TabHost tabHost = getTabHost();       

            tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("whatever").setContent(new Intent(this, SFilterStatsActivity.class)));
            tabHost.setCurrentTab(1);

        }

    /** Verweise auf die anderen Seiten **/
public void onClickADConfig(View view){
    final Intent i = new Intent(this, ADFilterConfigActivity.class);
    startActivity(i); }


    }

The linked class from my Tabhost looks for example like this:

    package de.retowaelchli.filterit;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;


public class ADFilterStatsActivity extends ListActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListContent));   
    }  

    private static String[] mListContent={"Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3","Item 1", "Item 2", "Item 3"};
} 

So you see, i got a TabHost with one tab in it, which is filled from my ListActivity, the tabhost should be hidden (invisible), over this hidden tab should be the tablerow visible. So i can click it to get to my other class. I hope this helps you guys...

FOUND A SOLUTION THX Egon

And here is the solution

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


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >



       <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <RelativeLayout
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
       <FrameLayout
           android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:layout_weight="1" />
       <TabWidget
           android:id="@android:id/tabs"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_alignBottom = "@android:id/tabcontent" 
           android:visibility="invisible"/>
       <TableRow android:layout_height="wrap_content" android:id="@+id/ADFilterOverview" android:layout_width="match_parent" android:onClick="onClickADConfig" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true">
           <TextView android:layout_gravity="bottom|left" android:text="@string/newadfilter" style="@style/NormalFont"></TextView>
       </TableRow>
       </RelativeLayout>
      </TabHost>


  </FrameLayout>


If you want to place one View at the top of the other in Z-axis, you can use FrameLayout. It lets you position a View on the background and other views on top of it. It's really powerful and easy to use, so you must give it a try. Hope this helps.


If you make Parentview invisible then its childview also automatically make invisible. In this scenario you have to define other layout for your new tab.

If this is not correct, please make edit in, or suggest me. Thanx

EDIT: on your xml code I think tabhost is a parentview and tablerow , textview are childview of it.


I believe the problem is that you set the tabwidget to be alignParentBottom and then you set TableRow to have aligntop the tabwidget. Thus it is not visible. Making the tabwidget invisible does hide it, but the place holder is still there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号