Question

I have created ViewPager and tabs. But unfortunately the fragments have added not below the titel of the tabs. I want that the fragment (LoginFragment and ProfleFragment) were located below titles of tabs (Login). How can I do it? Now they look this way (disgusting view): enter image description here

It's not possible to see textview "username" and texfield for username

How can I cange xml laoyout or add code to locate them correctly?

Here is my code:

profilefragment.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

        <ImageView
            android:contentDescription="@string/photoDesc_en"
            android:id="@+id/photo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/userInfo"
            android:src="@drawable/standarduserphoto" />


         <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/userInfo"
            android:layout_alignParentRight="true"
            >  

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/username_en"


             /> 

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userNameTextView"
             />  

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/email_en"
             /> 

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:id="@+id/emailTextView"
             /> 


         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/birthdate_en"
             /> 


           <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:id="@+id/birthDateTextView"
             /> 

           <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
               android:text="@string/gender_en"
             /> 


           <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:id="@+id/genderTextView"
             /> 

        </LinearLayout>
</RelativeLayout>

activity_fullscreen.xml

<android.support.v4.view.ViewPager 

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</android.support.v4.view.ViewPager>

loginfragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          >
          <!--  Log In Label -->
          <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372c24"
                android:text="@string/login_en"/>
          <EditText 
                android:id="@+id/logInTextField"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:singleLine="true"
                />
          <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372c24"
                android:text="@string/password_en"/>

          <EditText android:layout_width="fill_parent"
                android:id="@+id/passwordTextField"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:inputType="textPassword"
                />
          <!-- Login button -->
          <Button android:id="@+id/btnLogin"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/login_en"/>
</LinearLayout>

ProfileFragment.java

package com.example.vklogin;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ProfileFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.profilefragment, container, false);

        return rootView;
    }
}

MainActivity.java

package com.example.vklogin;

import com.example.adapter.TabsPagerAdapter;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends FragmentActivity implements TabListener {

    private ViewPager viewPager;
    private TabsPagerAdapter mAdapter;
    private ActionBar actionBar;
    private Button logIn,logOut;
    private EditText passwordField,userNameField;
    // Tab titles
    private String[] tabs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        //LinearLayout userInfoLayout = (LinearLayout) View.inflate(this, R.layout.loginfragment, null);

        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        

        tabs  = getResources().getStringArray(R.array.tabViews_en);

        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }

        /**
         * on swiping the viewpager make respective tab selected
         * */
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // on changing the page
                // make respected tab selected
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // on tab selected
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }


    ///
    private OnClickListener authorizeClick=new OnClickListener(){
        @Override
        public void onClick(View v) {
            //startLoginActivity();
        }
    };


    private void startLoginActivity() {
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    }

    private void setupUI() {
        logIn=(Button)findViewById(R.id.btnLogin);
        logIn.setOnClickListener(authorizeClick);
        passwordField=(EditText)findViewById(R.id.passwordTextField);
        userNameField=(EditText)findViewById(R.id.logInTextField);
    }
}

LogInFragment.java

package com.example.vklogin;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class LogInFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.loginfragment, container, false);

        return rootView;
    }



}

TabsPagerAdapter.java

package com.example.adapter;

import com.example.vklogin.LogInFragment;
import com.example.vklogin.ProfileFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


    public class TabsPagerAdapter extends FragmentPagerAdapter {

        public TabsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int index) {

            switch (index) {
            case 0:
                // Top Rated fragment activity
                return new LogInFragment();
            case 1:
                // Games fragment activity
                return new ProfileFragment();
            }

            return null;
        }

        @Override
        public int getCount() {
            // get item count - equal to number of tabs
            return 2;
        }

    }

AndroidMafiest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.vklogin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.vklogin.MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Was it helpful?

Solution

Try removing the activoty's theme from the manifest and see if it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top