简体   繁体   中英

Android studio frame layout not showing up in activity_main

I'm trying to design my on tabsView, so I created framelayout,called view_tabs.xml ,with all the buttons and with background and everything else and its preview looks fine, then I created class for this tabLayout called: TabsView , in which I inflated that framelayout, I connected all ImageViews to their id's and tried to add this view to activity_main.xml but when I add it I see only shape of this layout, there are no button images, no background, nothing at all.

Here's 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>

Here's 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) {

    }
}

and 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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM