I want to generate the relative layout dynamically So that i can repeat the data as much as many times i get data from the server .The layout id that i want to create dynamically are depart_flight_details_duration,passenger_details_layout.How could create them in a loop so that it will be repeated more than one .Please help me on this i am new in android.
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="#drawable/logo_demo" />
<ScrollView
android:id="#+id/main_scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imgLogo" >
<RelativeLayout
android:id="#+id/main_ScrollView_Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/trip_details_main"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="#drawable/flight_detail"
android:gravity="center_vertical" >
<TextView
android:id="#+id/trip_locations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/depart_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trip_locations"
android:layout_marginLeft="5dp"
android:text="18 Sep 2013"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="#+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:src="#drawable/cal" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_itin_header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="#+id/trip_details_main"
android:layout_marginTop="2dp"
android:background="#drawable/gray"
android:gravity="center_vertical" >
<TextView
android:id="#+id/itinerary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:layout_marginTop="5dp"
android:text="Itinerary Details"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/passenger_details_layout"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="#+id/travel_itin_header"
android:layout_marginTop="2dp"
android:background="#drawable/gray"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/pax_image"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:padding="3dip"
android:src="#drawable/black_man" />
<TextView
android:id="#+id/first_pax_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pax_image"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/pax_image"
android:text=" XXX XXX XXX"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/first_pax_name"
android:layout_alignParentRight="true"
android:src="#drawable/arrow2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/depart_flight_details_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/passenger_details_layout"
android:layout_marginTop="2dp"
android:background="#drawable/small_search" >
<ImageView
android:id="#+id/flight_depart_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="3dip"
android:src="#drawable/dep" />
<TextView
android:id="#+id/depart_return_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/flight_depart_image"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/arrow_image"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/one_way_date_and_duration_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_return_location"
android:layout_marginLeft="12dp"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="18 Sep 2013 09:45 | Duration 2:45"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<ImageView
android:id="#+id/arrow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/depart_return_location"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:src="#drawable/arrow2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_agency_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_flight_details_duration"
android:layout_marginTop="2dp"
android:background="#drawable/travelagency_bg" >
<TextView
android:id="#+id/travel_agency_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Travel Agency"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tarvel_agency_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_header"
android:layout_marginTop="2dp" >
<ImageView
android:id="#+id/agent_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/mobile_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/agent_logo"
android:src="#drawable/mobile" />
<ImageView
android:id="#+id/at_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/mobile_logo"
android:src="#drawable/at" />
<ImageView
android:id="#+id/email_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/at_logo"
android:src="#drawable/at" />
<TextView
android:id="#+id/travel_agency_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/agent_logo"
android:layout_marginLeft="5dp"
android:text="Address : XXXXXXXX"
android:textColor="#676767" />
<TextView
android:id="#+id/travel_agency_fax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_address"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:text="Fax : XXXXXXXX"
android:textColor="#676767" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remarks_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tarvel_agency_details"
android:layout_marginTop="2dp"
android:background="#drawable/general_remar" >
<TextView
android:id="#+id/genral_remark_header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Genral Remarks"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remark_text_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genral_remarks_header"
android:layout_marginTop="2dp" >
<TextView
android:id="#+id/genral_remark_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="HAVE A NICE TRIP"
android:textColor="#676767" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You have to use custom listview.
And for two listview in one layout see this link Link
A Simple Program for LayoutInflater from here
a-make this layout as your activity_main.xml-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
b-this is the hidden layout which we will add dynamically,save it as hidden_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/hidden_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, this is the inflated text of hidden layout"/>
<EditText
android:id="#+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, this is your name"/>
</LineraLayout>
c- Now this is the code for main activity-
public class MainActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<numberOfRows;i++){
LinearLayout main = (LinearLayout)findViewById(R.id.main_layout);
View view = getLayoutInflater().inflate(R.layout.hidden_layout, main,false);
main.addView(view);
}
}
}
RelativeLayout mDisplayBlock = (RelativeLayout)
LayoutInflater.from(getActivity()).inflate(
depart_flight_details_duration, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mDisplayBlock.setLayoutParams(params);
you can add this layout to your main scroll view
main_scroll_view_layout.addView(mDisplayBlock);
just put this code at appropriate place in your code.
Related
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar"/>
<ScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_above="#+id/makeOffer"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/firstcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_8dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp"
android:layout_marginTop="#dimen/padding_8dp"
app:cardCornerRadius="#dimen/padding_4dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp">
<RelativeLayout
android:id="#+id/insidecardone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/padding_4dp">
<TextView
android:id="#+id/constant_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/padding_4dp"
android:text="Charge per day"
android:textSize="#dimen/text_size_big_16" />
<EditText
android:id="#+id/tvRentPerday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:hint="Rs. "
android:gravity="center"
android:inputType="number"
android:maxLength="4"
android:textColor="#android:color/black"
android:textSize="#dimen/text_size_big_16" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/insidecardtwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/insidecardone"
android:layout_margin="#dimen/padding_4dp">
<TextView
android:id="#+id/con_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Duration (Days)"
android:textSize="#dimen/text_size_big_16" />
<TextView
android:id="#+id/num_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
android:paddingEnd="#dimen/padding_16dp"
android:paddingRight="#dimen/padding_24dp"
android:text="10"
android:textSize="#dimen/text_size_big_16"
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/insidecardtwo"
android:layout_margin="#dimen/padding_8dp"
android:background="#color/grey_lighter" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/insidecardtwo"
android:layout_margin="#dimen/padding_4dp"
android:paddingBottom="#dimen/padding_8dp"
android:paddingTop="#dimen/padding_24dp">
<TextView
android:id="#+id/total_constant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="#dimen/padding_4dp"
android:gravity="center_vertical"
android:text="Total Amount"
android:textSize="#dimen/text_size_big_16" />
<TextView
android:id="#+id/tvAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:textColor="#ff4f00"
android:textSize="#dimen/text_size_big_16"
android:textStyle="bold" />
<TextView
android:id="#+id/total_constant_mutterfly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/total_constant"
android:paddingTop="#dimen/padding_4dp"
android:text="#string/process_fee_text"
android:textColor="#android:color/darker_gray"
android:textSize="8sp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/middlecard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/firstcard"
android:layout_marginBottom="#dimen/padding_8dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp"
app:cardCornerRadius="#dimen/padding_4dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_8dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp">
<RelativeLayout
android:id="#+id/middlecard_relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="#dimen/padding_4dp">
<TextView
android:id="#+id/deposite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="#dimen/padding_4dp"
android:gravity="center_vertical"
android:text="Deposit"
android:textSize="#dimen/text_size_big_16" />
<TextView
android:id="#+id/knowmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/deposite"
android:text="#string/txt_know_more"
android:layout_marginTop="#dimen/padding_8dp"
android:textSize="#dimen/text_size_extra_extra_small_10"
/>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:inputType="number"
android:paddingEnd="#dimen/padding_16dp"
android:paddingRight="#dimen/padding_16dp"
android:textColor="#android:color/black"
android:textSize="#dimen/text_size_big_16" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/middletwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/middlecard_relative"
android:layout_margin="#dimen/padding_4dp"
android:visibility="gone"
>
<TextView
android:id="#+id/middle_con_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Charge (Rs.)"
android:textSize="#dimen/text_size_big_16" />
<EditText
android:id="#+id/etDeposit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:paddingEnd="#dimen/padding_16dp"
android:paddingRight="#dimen/padding_16dp"
android:hint="1000"
android:maxLength="4"
android:inputType="number"
android:textSize="#dimen/text_size_big_16"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/seccard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/middlecard"
android:layout_marginBottom="#dimen/padding_8dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp"
app:cardCornerRadius="#dimen/padding_4dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/describe_constant_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/padding_8dp"
android:text="Describe Your item"
android:textColor="#ff4f00"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/rlTohide"
android:layout_marginTop="#dimen/padding_4dp"
android:layout_width="160dp"
android:layout_height="120dp"
android:background="#drawable/greyborder_transparentbg"
>
<ImageView
android:id="#+id/img1"
android:layout_centerInParent="true"
android:layout_width="40dp"
android:src="#drawable/addimg"
android:layout_height="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/img1"
android:text="(Optional)"
android:textSize="#dimen/text_size_extra_extra_small_10"
android:textColor="#color/text_grey_opc"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<ImageView
android:visibility="gone"
android:id="#+id/imgResource"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginTop="#dimen/padding_8dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp"
android:layout_marginTop="180dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/insidecardone"
android:layout_margin="#dimen/padding_4dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp">
<TextView
android:id="#+id/con_product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="8dp"
android:text="Name Of Product"
android:textSize="#dimen/text_size_big_16" />
<EditText
android:id="#+id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#+id/con_product_name"
android:layout_toRightOf="#+id/con_product_name"
android:layout_alignParentRight="true"
android:hint="E.g. Nikon DSLR"
android:paddingEnd="#dimen/padding_16dp"
android:paddingRight="#dimen/padding_16dp"
android:maxLength="30"
android:inputType="textPersonName"
android:layout_marginLeft="#dimen/padding_16dp"
android:layout_marginStart="#dimen/padding_16dp"
android:textColor="#android:color/black"
android:textSize="#dimen/text_size_big_16"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/insidecardtwo"
android:layout_margin="#dimen/padding_4dp"
android:layout_marginBottom="#dimen/padding_8dp"
android:layout_marginLeft="#dimen/padding_8dp"
android:layout_marginRight="#dimen/padding_8dp">
<TextView
android:id="#+id/Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Description :"
android:textSize="#dimen/text_size_big_16" />
<EditText
android:id="#+id/desc_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Description"
android:hint="E.g. Comes with 18-55 mm lens, charger and carry case"
android:layout_marginTop="#dimen/padding_8dp"
android:background="#drawable/white_border_request_screen"
android:textColor="#android:color/darker_gray"
android:textSize="#dimen/text_size_big_16" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/makeOffer"
android:layout_width="match_parent"
android:layout_height="#dimen/padding_48dp"
android:layout_alignParentBottom="true"
android:background="#color/new_primary_text"
android:padding="#dimen/padding_8dp"
android:text="#string/txt_make_offr"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_18"
/>
</RelativeLayout>
Android Manifest
<activity
android:name=".MyActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"/>
I am working on the layout since last night and I tried almost solution which I known. I am new in Android so please suggest me what is wrong with this layout.
this "fillViewport" work for another screen but with this screen it's not working.
Add android:windowSoftInputMode="stateHidden|adjustResize" to your <activity> tag in AndroidManifest.xml file. This will cause the screen to be resized to the left over space after the soft keyboard is shown. So, you will be able to scroll easily.
One more thing set property of ScrollView to the android:layout_above to the Button on the bottom of the page.
UpDate :
add this line to your ScrollView.
android:layout_above="#+id/makeOffer"
like this way
<ScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_above="#+id/makeOffer">
ScreenShot :
I have a relative layout with an image and title.Below the relativelayout I have an Editext(used for searching which will display a search result listview based on change of text in the edittext).So once i touch on the EDITExt softkeyboard will appear and the top layout's visibility is set to 'Gone'.It works fine but sometimes the edittext moves up but the top layout is visible like ui frozen and this will disapppear when we enter a keystroke for edittext.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/violetbg"
android:id="#+id/parentt"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/framestepone"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/framestepone"
>
<RelativeLayout
android:layout_height="#dimen/titlebarsize"
android:layout_width="match_parent"
android:background="#color/red"
android:layout_alignParentTop="true"
android:id="#+id/topbar"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
style="#style/actionbarphonetextviewstyle"
android:text="#string/steponetitle"
android:id="#+id/steponetitle"
/>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/sidemenutest"
android:id="#+id/sidemenu"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:background="#null"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/initlay"
android:layout_height="wrap_content"
android:layout_below="#+id/topbar"
android:layout_marginTop="3dp"
android:layout_width="match_parent">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/layyy"
>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steptag"
android:text="#string/steptagg"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
/>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steponetag"
android:text="#string/onetag"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/steptag"
android:layout_marginTop="5dp"
/>
<ImageView
android:id="#+id/steponebg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/stepone"
android:layout_below="#+id/steponetag"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steponetext"
android:text="#string/chooser"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/steponebg"
android:textAllCaps="true"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativebag"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/initlay"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
>
<RelativeLayout
android:id="#+id/relativebagforlist"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_centerHorizontal="true"
>
<EditText
android:layout_height="60dp"
android:layout_width="match_parent"
android:hint="Search & Preview Song"
android:id="#+id/searchsong"
android:inputType="textNoSuggestions"
android:textColor="#color/black"
android:textSize="#dimen/text_size_small"
android:background="#drawable/steponetextboxbg"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true"
android:paddingLeft="12dp"
android:imeOptions="actionDone"
android:paddingRight="8dp"
/>
<RelativeLayout
android:layout_height="60dp"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/steponetextboxbg"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:id="#+id/parntrecrd"
>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:id="#+id/lay"
android:layout_marginLeft="10dp"
>
<ImageButton
android:id="#+id/playbtns"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/play"
android:background="#null"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
/>
<ImageButton
android:id="#+id/pausebtns"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/pause"
android:background="#null"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
android:visibility="gone"
/>
</RelativeLayout>
<TextView
android:id="#+id/txtsearche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/lay"
android:background="#color/white"
android:clickable="true"
android:gravity="center_vertical"
android:hint="search song"
android:inputType="none"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/black"
android:textSize="#dimen/text_size_small" />
</RelativeLayout>
</RelativeLayout>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/question"
android:background="#null"
android:layout_below="#+id/relativebagforlist"
android:layout_alignRight="#+id/relativebagforlist"
android:layout_marginTop="5dp"
android:id="#+id/btnhelp"
android:layout_marginRight="10dp"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignTop="#+id/btnhelp"
android:layout_alignBottom="#+id/btnhelp"
android:layout_toLeftOf="#+id/btnhelp"
android:layout_marginRight="5dp"
android:layout_below="#+id/relativebagforlist"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/hlptxt"
android:layout_marginTop="5dp"
android:text="#string/help"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<Button
android:layout_height="#dimen/btnheights"
android:layout_width="match_parent"
android:text="#string/readybutton"
android:id="#+id/btnready"
android:textColor="#color/white"
android:background="#drawable/buttonbackground"
style="#style/actionbarphonetextviewstyle"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:textAlignment="center"
/>
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/lstsongs"
android:background="#color/white"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:clickable="true"
android:layout_marginTop="10dp"
android:layout_below="#+id/relativebagforlist"
/>
<TextView
android:layout_height="60dp"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:layout_below="#+id/relativebagforlist"
android:background="#color/white"
android:text="#string/nomatch"
android:id="#+id/nomatchtext"
android:textColor="#color/black"
android:paddingLeft="10dp"
android:gravity="center_vertical"
/>
</RelativeLayout>
<!-- ******************************************** -->
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/progrest"
android:visibility="gone"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</RelativeLayout>
and my code after clicking the textview which will invoke the softkeyboard making the edittext visible and top layout gone is as follows
txtsearch.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
temptext=(txtsearch.getText().toString());
help.setVisibility(View.GONE);
helptext.setVisibility(View.GONE);
txtrecord.setVisibility(View.GONE);
searchsong.setVisibility(View.VISIBLE);
steptag.setVisibility(View.GONE);
steponetag.setVisibility(View.GONE);
steponebg.setVisibility(View.GONE);
steponetext.setVisibility(View.GONE);
lay.setVisibility(View.GONE);
searchsong.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(searchsong, InputMethodManager.SHOW_FORCED);
searchsong.setText(temptext);
if(myMap.size()==0){
new Getsongs().execute();
}
}
});
I solved it by removing android:windowSoftInputMode="adjustResize|stateHidden"
from my manifest
I want to inflate Relative Layout in a Relative Layout .But it is inflating it only one time after that it is not inflating please help me what is the problem in my code.
Activity Code
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout main = (RelativeLayout)findViewById(R.id.passenger_details_layout);
for(int i=0;i<9;i++){
View view = getLayoutInflater().inflate(R.layout.passenger_details_layout, main,false);
main.addView(view);
}
After #Ritaban Suggestion and Help this what i have done
Activity Code:
LayoutInflater inflater;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_itineary_page);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
/*
* LayoutInflater inflater = (LayoutInflater) getBaseContext()
* .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
*/
LinearLayout main = (LinearLayout) findViewById(R.id.main_passenger_details_layout);
for (int i = 0; i < 2; i++) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(
R.layout.passenger_details_layout, main, false);
main.addView(layout, i);
}
RelativeLayout lay = (RelativeLayout) findViewById(R.id.thingstoshowbelow);
RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) lay
.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.main_passenger_details_layout);
lay.setLayoutParams(params);
lay.setVisibility(View.VISIBLE);
}
Main.XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="#drawable/logo_demo" />
<ScrollView
android:id="#+id/main_scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imgLogo" >
<RelativeLayout
android:id="#+id/main_ScrollView_Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/trip_details_main"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="#drawable/flight_detail"
android:gravity="center_vertical" >
<TextView
android:id="#+id/trip_locations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/depart_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trip_locations"
android:layout_marginLeft="5dp"
android:text="18 Sep 2013"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="#+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:src="#drawable/cal" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_itin_header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="#+id/trip_details_main"
android:layout_marginTop="2dp"
android:background="#drawable/gray"
android:gravity="center_vertical" >
<TextView
android:id="#+id/itinerary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:layout_marginTop="5dp"
android:text="Itinerary Details"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:id="#+id/main_passenger_details_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_itin_header"
android:layout_marginTop="2dp"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="#+id/thingstoshowbelow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/passenger_details_layout"
android:visibility="gone" >
<RelativeLayout
android:id="#+id/depart_flight_details_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:background="#drawable/small_search" >
<ImageView
android:id="#+id/flight_depart_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="3dip"
android:src="#drawable/dep" />
<TextView
android:id="#+id/depart_return_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/flight_depart_image"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/arrow_image"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/one_way_date_and_duration_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_return_location"
android:layout_marginLeft="12dp"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="18 Sep 2013 09:45 | Duration 2:45"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<ImageView
android:id="#+id/arrow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/depart_return_location"
android:layout_alignParentRight="true"
android:layout_marginRight="12dp"
android:layout_marginTop="10dp"
android:src="#drawable/arrow2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_agency_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_flight_details_duration"
android:layout_marginTop="2dp"
android:background="#drawable/travelagency_bg" >
<TextView
android:id="#+id/travel_agency_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Travel Agency"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tarvel_agency_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_header"
android:layout_marginTop="2dp" >
<ImageView
android:id="#+id/agent_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/uniglobe_logo" />
<ImageView
android:id="#+id/mobile_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/agent_logo"
android:src="#drawable/mobile" />
<ImageView
android:id="#+id/at_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/mobile_logo"
android:src="#drawable/at" />
<ImageView
android:id="#+id/email_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/at_logo"
android:src="#drawable/at" />
<TextView
android:id="#+id/travel_agency_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/agent_logo"
android:layout_marginLeft="5dp"
android:text="XXXXXXXXXXXXXXXXXXXX"
android:textColor="#676767" />
<TextView
android:id="#+id/travel_agency_fax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_address"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:text="Fax : 2345678"
android:textColor="#676767" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remarks_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tarvel_agency_details"
android:layout_marginTop="2dp"
android:background="#drawable/general_remar" >
<TextView
android:id="#+id/genral_remark_header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Genral Remarks"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remark_text_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genral_remarks_header"
android:layout_marginTop="2dp" >
<TextView
android:id="#+id/genral_remark_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="HAVE A NICE FLIGHT"
android:textColor="#676767" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</ScrollView>
Use Linear layout as the parent View and give android:orientation = "vertical". Relative Layout is a a Layout where the positions of the children are described in relation to each other or to the parent.If you want to use relative layout then you have to use the addrule property or else all the child will be drawn over the previous child.
For ex :
<Linearlayout
android:id="#+id/passenger_details_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_itin_header"
android:layout_marginTop="2dp"
android:gravity="center_vertical"
android:orientation = "vertical" >
</Linearlayout>
And in activity:
LayoutInflater inflater = (LayoutInflater)getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout main =(LinearLayout)findViewById(R.id.passenger_details_layout);
for(int i=0;i<9;i++){
View view = inflater.inflate(R.layout.passenger_details_layout, null);
main.addView(view);
}
LayoutInflater is working and nine time layout is adding. But you cannot see the all views since all Layouts are having adding to another RelativeLayout so they are adding one over the other.
So inorder to overcome that use LinearLayout with orientation vertical instead of Relativelayout in parent view
Every time you add view to that Relative Layout it is being added at the same position..like stack of views..u can't see the below view..better try LinearLayout .. views will be added horizontally or vertically..so u can see that nine views..
// Replace this line
View view = getLayoutInflater().inflate(R.layout.passenger_details_layout, main,false);
to
View view = getLayoutInflater().inflate(R.layout.passenger_details_layout, null);
Okay this is your solution copy and paste it in your main xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="#drawable/ic_launcher" />
<ScrollView
android:id="#+id/main_scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imgLogo" >
<RelativeLayout
android:id="#+id/main_ScrollView_Container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/trip_details_main"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="#android:color/holo_blue_dark"
android:gravity="center_vertical" >
<TextView
android:id="#+id/trip_locations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/depart_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trip_locations"
android:layout_marginLeft="5dp"
android:text="18 Sep 2013"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<ImageView
android:id="#+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="12dp"
android:src="#android:color/holo_blue_bright" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_itin_header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="#+id/trip_details_main"
android:layout_marginTop="2dp"
android:background="#android:color/holo_blue_light"
android:gravity="center_vertical" >
<TextView
android:id="#+id/itinerary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:layout_marginTop="5dp"
android:text="Itinerary Details"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Relative1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_itin_header"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/main_passenger_details_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/depart_flight_details_duration"
android:layout_width="wrap_content"
android:layout_below="#+id/Relative1"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="2dp"
android:background="#android:color/holo_blue_bright" >
<ImageView
android:id="#+id/flight_depart_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="3dip"
android:src="#android:color/holo_blue_bright" />
<TextView
android:id="#+id/depart_return_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/flight_depart_image"
android:layout_marginLeft="12dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/arrow_image"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="Delhi to Hydrabad"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/one_way_date_and_duration_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_return_location"
android:layout_marginLeft="12dp"
android:layout_toRightOf="#+id/flight_depart_image"
android:text="18 Sep 2013 09:45 | Duration 2:45"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<ImageView
android:id="#+id/arrow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/depart_return_location"
android:layout_alignParentRight="true"
android:layout_marginRight="12dp"
android:layout_marginTop="10dp"
android:src="#android:color/holo_blue_bright" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/travel_agency_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/depart_flight_details_duration"
android:layout_marginTop="2dp"
android:background="#android:color/holo_blue_bright" >
<TextView
android:id="#+id/travel_agency_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Travel Agency"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/tarvel_agency_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_header"
android:layout_marginTop="2dp" >
<ImageView
android:id="#+id/agent_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#android:color/holo_blue_bright" />
<ImageView
android:id="#+id/mobile_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/agent_logo"
android:src="#android:color/holo_blue_bright" />
<ImageView
android:id="#+id/at_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/mobile_logo"
android:src="#android:color/holo_blue_bright" />
<ImageView
android:id="#+id/email_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/at_logo"
android:src="#android:color/holo_blue_bright" />
<TextView
android:id="#+id/travel_agency_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/agent_logo"
android:layout_marginLeft="5dp"
android:text="XXXXXXXXXXXXXXXXXXXX"
android:textColor="#676767" />
<TextView
android:id="#+id/travel_agency_fax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/travel_agency_address"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:text="Fax : 2345678"
android:textColor="#676767" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remarks_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tarvel_agency_details"
android:layout_marginTop="2dp"
android:background="#android:color/holo_blue_bright" >
<TextView
android:id="#+id/genral_remark_header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Genral Remarks"
android:textColor="#676767"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/genral_remark_text_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genral_remarks_header"
android:layout_marginTop="2dp" >
<TextView
android:id="#+id/genral_remark_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="HAVE A NICE FLIGHT"
android:textColor="#676767" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
and for activity put this
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout main = (LinearLayout) findViewById(R.id.main_passenger_details_layout);
for (int i = 0; i < 9; i++) {
LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.activity_second, main, false);
main.addView(row);
}
}
Every body I want to call another XML in my activity , i called my main xml as given below
setContentView(R.layout.main);
and my xml file is as follow-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/appbg"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ll2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- listview -->
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="#drawable/logo12"
android:src="#drawable/logo12" />
<LinearLayout
android:id="#+id/homeLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="right" >
<Button
android:id="#+id/btnCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/cart_icon" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/home" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/searchLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/search"
android:textColor="#color/Black"
android:textSize="15sp" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/cross1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="5dp"
android:contentDescription="#drawable/search"
android:src="#drawable/search" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linSortby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvsortby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sortby"
android:textColor="#color/Blue"
android:textSize="13sp" />
<TextView
android:id="#+id/tvPriceLH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priceLH"
android:textColor="#color/Blue"
android:textSize="13sp" />
<TextView
android:id="#+id/tvPriceHL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="#string/priceHL"
android:textColor="#color/Blue"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linPagingupper"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linPaging"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:contentDescription="#drawable/prev"
android:src="#drawable/prev" />
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/buttonbackground"
android:text="#string/n1"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n2"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n3"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n4"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n5"
android:textColor="#color/Blue"
android:textSize="12sp" />
<!-- button -->
<ImageView
android:id="#+id/imgNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:contentDescription="#drawable/next"
android:src="#drawable/next" />
</LinearLayout>
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/n1"
android:textColor="#color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/listViewResult"
android:layout_width="fill_parent"
android:layout_height="320dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bluegrad"
android:gravity="bottom"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:contentDescription="#drawable/contact"
android:src="#drawable/contact" />
<LinearLayout
android:id="#+id/bottomLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageView
android:id="#+id/imgHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:contentDescription="#drawable/home"
android:src="#drawable/home" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/add_other_xml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
and i want to call another activity by following code-
LinearLayout lin_lay_add_paynow =
(LinearLayout)findViewById(R.id.add_other_xml);
View pay_now_view = getLayoutInflater().inflate(R.layout.pay_now_btn, null);
lin_lay_add_paynow.addView(pay_now_view);
TextView btn_pay_now = (TextView) pay_now_view.findViewById(R.id.btn_paynow);
btn_pay_now.setText("mlsdmlsm");
and my pay_now_btn.xml is as follow
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/btn_paynow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
And problem is that i am doing every thing in correct manner . Then why my textview is not appearing . No error no exception then i am not able to see my textview of pay_now_btn.xml
Thanks in advance to all.
You have setContentView(R.layout.main).
And you are inflating a view. But the inflated view is not added to the layout.
Have a another LinearLayout in your main.xml. Place this linear layout to the required position or you can use Relativelayout.
Initialize it in onCreate
LinearLayout ll = LinearLayout findViewById(R.id.ll);
Now add the inflated view to linearlayout
ll.addView(pay_now_view);
Edit:
You can add the infalted view as a footer to listview as
list.addFooterView(pay_now_view );
You have not added the view into a layout in your main.xml
Create a layout in your main.xml
In your code
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(pay_now_view);
Hope this works. Let me know if you face any problem
CODE :
Add this at bottom of main.xml before closing the last tag
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
</LinearLayout>
In your Activity after inflating and setText:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(pay_now_view);
I try to make view under other view progmaly my problem is that its dont seems to work.
The views not going below they view in my code.
The firstText and secondText arent going under the ID's i put.
Thank for helping :)
public void setHelper() {
linear1 = (LinearLayout) findViewById(R.id.checkHelp1);
linear2 = (LinearLayout) findViewById(R.id.layout2);
firstText = (TextView) findViewById(R.id.textView4);
secondText = (TextView) findViewById(R.id.timer);
linear1.setVisibility(View.GONE);
linear2.setVisibility(View.GONE);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp2.addRule(RelativeLayout.BELOW, R.id.checkNeedHelp);
firstText.setLayoutParams(lp2);
lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp2.addRule(RelativeLayout.BELOW, R.id.addNewExercise);
lp2.setMargins(0, 25, 0, 0);
secondText.setLayoutParams(lp2);
}
XML code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<EditText
android:id="#+id/editRoutine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/routines"
android:ems="10"
android:hint="add new routine"
android:textColorHint="#color/black" >
</EditText>
<TextView
android:id="#+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/layout2"
android:text="Routine exercsies" />
<Spinner
android:id="#+id/routineExercises"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/timer"
android:layout_toLeftOf="#+id/deleteExerciseFromRoutine" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/routineExercises"
android:text="Choose exercise to add to selected routine" />
<Spinner
android:id="#+id/exerciseForRoutine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_toLeftOf="#+id/addExercisesToRoutine" />
<ImageButton
android:id="#+id/addExercisesToRoutine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/exerciseForRoutine"
android:layout_alignParentRight="true"
android:src="#android:drawable/ic_input_add" />
<ImageButton
android:id="#+id/addNewRoutine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/routines"
android:src="#android:drawable/ic_input_add" />
<ImageButton
android:id="#+id/deleteExerciseFromRoutine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignParentRight="true"
android:src="#drawable/close" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/deleteExerciseFromRoutine"
android:layout_alignParentRight="true" />
<ImageButton
android:id="#+id/removeRoutine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/routines"
android:layout_toRightOf="#+id/routineExercises"
android:src="#drawable/close" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Edit Routines"
android:textSize="30sp" />
<LinearLayout
android:id="#+id/checkHelp1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/checkNeedHelp"
android:background="#color/gray"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manage routines"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add new routines or delete one from the list" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editRoutine"
android:layout_marginTop="25sp"
android:background="#color/gray"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Routine exercies"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add exercies to selected routine or delete one" />
</LinearLayout>
<LinearLayout
android:id="#+id/swipeLayOut2"
android:layout_width="110sp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#color/Black"
android:orientation="vertical"
android:visibility="gone" >
<Button
android:id="#+id/goHomePage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="home page"
android:textSize="15sp" />
<Button
android:id="#+id/goCalendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Calendar"
android:textSize="15sp" />
<Button
android:id="#+id/goLive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="live workout"
android:textSize="15sp" />
<Button
android:id="#+id/goToday"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Today log"
android:textSize="15sp" />
<Button
android:id="#+id/goProgram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Program plan"
android:textSize="15sp" />
<Button
android:id="#+id/goPersonal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pesonal detials"
android:textSize="15sp" />
<Button
android:id="#+id/goWorkout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set workout"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/checkHelp1"
android:text="Routines" />
<Spinner
android:id="#+id/routines"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_toLeftOf="#+id/removeRoutine" />
<CheckBox
android:id="#+id/checkNeedHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="25sp"
android:text="Need help?"
android:textSize="13sp" />
<com.example.workoutlog.VerticalTextView
android:id="#+id/swipeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/swipeLayOut2"
android:background="#color/red"
android:text="swipe right"
android:textSize="18sp" />
</RelativeLayout>
Layouts process their children in a top down fashion so any layout_above, layout_below etc must refer to a view physically above it in the layout file.
So before using layout_below put the xml of relevant view.
An example is below:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/contribution_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:textSize="72sp"
android:text="77"
tools:text="77"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#id/contribution_amount"
android:paddingTop="12sp"
android:textSize="28sp"
android:text="$"
tools:text="$"/>
</RelativeLayout>
Notice that the TextView with layout_toStartOf references a view that has been defined before itself. If I had put the TextView with the layout_toStartOf element before the contribution_amount TextView the layout would not work.