Android studio框架布局未显示在activity_main中

时间:2017-08-17 14:22:39

标签: java android xml

我试图设计我的tabView,所以我创建了framelayout,名为view_tabs.xml,带有所有按钮,背景和其他所有内容,预览看起来很好,然后我为这个tabLayout创建了类调用:TabsView,我在其中夸大了framelayout,我将所有ImageView连接到他们的ID并尝试将此视图添加到activity_main.xml但是当我添加它时,我只看到此布局的形状,没有按钮图像,没有背景,没有任何东西。

此处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) {

    }
}

和here's 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>

1 个答案:

答案 0 :(得分:0)

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