Joshi Yogesh
Joshi Yogesh

Reputation: 142

viewpager is not showing in activity

code of my XML file is given below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_exercise_one_questions"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="com.example.joshiyogesh.puzzle.ExerciseOneQuestions">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="What Number Replaces Question mark ? "/>
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_height="fill_parent"
        android:layout_width="wrap_content">
    </android.support.v4.view.ViewPager>


</LinearLayout>

initially it was showing , but after i added text-view in XML file its not showing in activity. any help would be appreciated. Since I'm knew , i couldn't find the what exactly reason.

edit : 1 what it should be , there would be textView below which there would be PageAdapter

Upvotes: 0

Views: 94

Answers (2)

Anko6
Anko6

Reputation: 41

In your code the linear layout orientation is vertical and you gave the textview(which is your first view) width = "match_parent" means it ll take all the available width and then you are adding your viewpager(which doesn't have any space remained). Change android:orientation="vertical" to android:orientation="horizontal" and it ll work.

Upvotes: 0

Junaid Hafeez
Junaid Hafeez

Reputation: 1616

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_exercise_one_questions"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="What Number Replaces Question mark ? "/>
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_height="fill_parent"
        android:layout_width="match_parent">
    </android.support.v4.view.ViewPager>


</LinearLayout>

Upvotes: 1

Related Questions