2017-08-17 70 views
0

我试图设计我的tabsView,所以我创建了framelayout,名为view_tabs.xml,所有的按钮和背景以及其他一切和它的预览看起来不错,然后我创建了类对于这个tabLayout调用:TabsView,其中我夸大了framelayout,我将所有ImageViews连接到它们的id并试图将此视图添加到activity_main.xml,但是当我添加它时,我只能看到此布局的形状,没有按钮图像,没有背景,一点都没有。Android工作室框架布局没有显示在activity_main

这里的view_tabs.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/homeTabsViewFrame" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:layout_gravity="bottom" 
    tools:background="@color/light_red"> 

    <ImageView 
     android:id="@+id/vst_center_image" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_gravity="center|bottom" 
     android:background="@drawable/ic_launcher" 
     android:layout_marginBottom="10dp"/> 
    <ImageView 
     android:id="@+id/vst_start_image" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_marginStart="24dp" 
     android:layout_gravity="start|bottom" 
     android:background="@drawable/gpsmapbutton" 
     android:layout_marginBottom="10dp"/> 
    <ImageView 
     android:id="@+id/vst_end_image" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_gravity="end|bottom" 
     android:layout_marginEnd="24dp" 
     android:background="@drawable/icon_black" 
     android:layout_marginBottom="10dp"/> 

    <View 
     android:id="@+id/vst_indicator" 
     android:layout_width="64dp" 
     android:layout_height="5dp" 
     android:layout_gravity="bottom|center" 
     android:layout_marginBottom="4dp" 
     android:background="@color/white"/> 
</FrameLayout> 

这里的TabsView.java

package com.hist_area.imeda.histarea.view; 

import android.content.Context; 
import android.support.v4.view.ViewPager; 
import android.util.AttributeSet; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.FrameLayout; 
import android.widget.ImageView; 

import com.hist_area.imeda.histarea.R; 

/** 
* Created by imeda on 8/16/17. 
*/ 

public class TabsView extends FrameLayout implements ViewPager.OnPageChangeListener { 
    private ImageView mCenterImage; 
    private ImageView mStartImage; 
    private ImageView mEndImage; 
    private View mIndicator; 


    public TabsView(Context context) { 
     this(context, null); 
    } 

    public TabsView(Context context, AttributeSet attrs) { 
     this(context, attrs,0); 
    } 

    public TabsView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(); 
    } 

    private void init() { 
     LayoutInflater.from(getContext()).inflate(R.layout.view_tabs,this,true); 
     mCenterImage = (ImageView) findViewById(R.id.vst_center_image); 
     mStartImage = (ImageView) findViewById(R.id.vst_start_image); 
     mEndImage = (ImageView) findViewById(R.id.vst_end_image); 
     mIndicator = (View) findViewById(R.id.vst_indicator); 
    } 

    @Override 
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 

    } 

    @Override 
    public void onPageSelected(int position) { 

    } 

    @Override 
    public void onPageScrollStateChanged(int state) { 

    } 
} 

和这里的activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:background="@color/black" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.hist_area.imeda.histarea.MainActivity"> 

    <View 
     android:id="@+id/home_tabs_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/lignt_blue" 
     android:alpha="0.5"/> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <com.hist_area.imeda.histarea.view.TabsView 
     android:id="@+id/homeTabsView" 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:layout_alignParentBottom="true"/> 
</RelativeLayout> 

回答

0

我不明白,但是,为什么不使用 '包括' 标签?