2017-08-17 67 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

我不明白,但是,爲什麼不使用 '包括' 標籤?