我想写一个类似QQ好友列表可以滑动的TAB界面,但写好后有一个问题,tab的选项卡被下面的内容覆盖了,如下图:图中那个btton是其中的一个Activity中的,按理说它不应该从最上面开始而已呀,请大神帮看看
下面是代码
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/touch_area" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
<!-- 这个LinerLayout 的目的是用来左右滑动切换选项卡的-->
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        >        <TabWidget           
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </TabWidget>        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent" >
        </FrameLayout>
    </TabHost></LinearLayout>
tab_indector.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/tab_wight_back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <!-- 
    <ImageView 
        android:id="@+id/indector_image"
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
        />
         -->
    
<TextView 
    android:id="@+id/indector_text"
    android:layout_width="150dp"
    android:layout_height="30dp"
    android:gravity="center"
    android:background="@android:color/transparent"
    />
    
</RelativeLayout>
MainActivity.java
package com.resume.activity;import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;public class MainActivity extends TabActivity implements OnTouchListener,OnGestureListener{

//定义手势的最小距离和速度
private static final int FLING_MIN_DISTANCE = 20;
private static final int FLING_MIN_VELOCITY = 0;

//?
GestureDetector mGestureDetector;

//布局组件
private TabHost tabs;
private LinearLayout touchArea;
private ImageView tab_title;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mGestureDetector=new GestureDetector(this);
//把触摸区域组件与触摸事件捆绑
touchArea=(LinearLayout)findViewById(R.id.touch_area);
touchArea.setOnTouchListener(this);
touchArea.setLongClickable(true);

tabs=getTabHost();
tabs.setup();

Intent intent=new Intent();
intent.setClass(this,IntroductionActivity.class);
tabs.addTab(createTab("introduction", intent));

intent=new Intent();
intent.setClass(this,ExperienceActivity.class);
tabs.addTab(createTab("experience", intent));

intent=new Intent();
intent.setClass(this,SkillAndJobActivity.class);
tabs.addTab(createTab("skill&job", intent));
}

private TabSpec createTab(String title,Intent intent){
TabSpec spec=tabs.newTabSpec("");
// tab_title.setText(title);
View v=LayoutInflater.from(this).inflate(R.layout.tab_indector, null);
TextView tv=(TextView)v.findViewById(R.id.indector_text);
tv.setText(title);

spec.setIndicator(v);
spec.setContent(intent);
return spec;
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("信息", "touch");
return mGestureDetector.onTouchEvent(event);
} @Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
} @Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub

} @Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
} @Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
} @Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub

} @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
int totle=tabs.getTabWidget().getChildCount();
int current=tabs.getCurrentTab();

if((e1.getX()-e2.getX())>FLING_MIN_DISTANCE&&Math.abs(velocityX)>FLING_MIN_VELOCITY){
Toast.makeText(getApplicationContext(), "left", Toast.LENGTH_LONG).show();
}else if((e2.getX()-e1.getX())>FLING_MIN_DISTANCE&&Math.abs(velocityX)>FLING_MIN_VELOCITY){
Toast.makeText(getApplicationContext(), "right", Toast.LENGTH_LONG).show();
}
return false;
}}Android布局覆盖

解决方案 »

  1.   

    你button的那个 layout呢?关键的xml  你没有给出啊
      

  2.   

    不好意思,昨天太晚了,有点晕introduction.xml
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:orientation="vertical" >
        
        <Button  
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"      
            android:text="introduction"/></RelativeLayout>
      

  3.   

    android:layout_marginTop="100dp" 去掉试试看
      

  4.   


    去掉的话,button会直接压到选项卡上面
      

  5.   

    View v=LayoutInflater.from(this).inflate(R.layout.tab_indector, null); 这句的parent 是应该有的吧?
    touchArea 应该是这个linearlayout
      

  6.   

    找到问题的原因了:我继承了Black主题,然后又把background设置成了#ffffff,所以白色区域就覆盖了选项卡,我现在改成Light主题,然后在布局文件里设置背景,问题解决了,谢谢你