As in the title. I want to have grid of pictures which consists of 2 columns and every picture must have the same dimensions. The user should be able to click on each picture to enter the full screen mode and then slide pictures from left to right (full sized pictures in that mode). By far, I made a grid of clickable elements but without functionality of sliding them. Here is my code:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.miki.androidtwo.MainActivity">
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:scrollbars="vertical"
android:gravity="center">
</GridView>
</RelativeLayout>
activity_full_image.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.example.miki.androidtwo.FullImageActivity">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="I want to see other doggos" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.grid);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(this));
/**
* On Click event for Single Gridview Item
* */
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}
Other classes are FullImageActivity and ImageAdapter; they are pretty obvious and simple so I won't post them.
How can I implement this sliding pictures functionality?
How can i determine dimensions of pictures in a grid that will be independent of the device?
Actually I think I hard-coded it with the line:
imageView.setLayoutParams(new GridView.LayoutParams(480,402));
If you want to slide the images while they are not full screen, you can use a HorizontalScrollView, or if you want to slide them while they are fullscreen, you can use a ViewPager, along with a PagerAdapter.
So to populate the grid imageView.setLayoutParams is fine to use for setting the size of each imageview like the way you did. When a user clicks on an image, you are going to go to a new Activity that is setup with a ViewPager and a PagerAdapter. This way the user can slide through fullscreen images.
Related
I have a page in which I'm taking the START TIME and END TIME from DATABASE.
Let's say the START TIME is 7:00 and END TIME is 22:00
I want to use this START TIME and END TIME to show in my page as textview like 7:00 8:00 9:00 and sooo on till 22:00 as textview
Also I have an imageview that will also increase when the text increases.
How can I achieve this?
Also I want the result text in Horizontal Scroll View with Imageview at top and text view as bottom of each imageview
char first = StartTime.charAt(0);
int StartTimeint = Integer.parseInt(String.valueOf(first));
int l;
for( l = StartTimeint; l<=22; l++){
Log.d("SeatsPage", "Time is "+l);
}
timeofseats.setText(Integer.toString(l));
This is I have done so far but I'm getting 23 as a result, the textview is not increasing
This is my XML File
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="#+id/llMain"
android:layout_height="match_parent"
tools:context=".SeatsPagewithDB.SeatsPage">
<ImageView
android:id="#+id/imageView11"
android:layout_width="150px"
android:layout_height="150px"
android:layout_marginStart="28dp"
android:layout_marginEnd="326dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/seat" />
<TextView
android:id="#+id/timeofseats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="334dp"
android:background="#FF0000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="7:00"
android:textColor="#fff"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView11" />
</android.support.constraint.ConstraintLayout>
This is the result I am getting as layout
This what I want programmatically
The XML code that you write in your layout.xml file to create the UI is for static UI only. What you are asking is to create views dynamically during runtime. Although you can definitely create views using java code on a click of a button or something. But it is better to code less for the UI whenever possible and keep it separated from the program code. Instead use the tools given to us by the framework we are using.
In Android those tools include stuff like ListView, GridView and the newer and better RecyclerView. These views help you add other views dynamically to your UI in runtime. You define one of them or more (depending on your UI needs) once in your layout.xml and configure them using java code like any other view.
This is how you can use RecyclerView to achieve your goal. I can't explain everything how RecyclerView works and what each line of code does as it will make a very long post but I have tried to highlight main things briefly.
1. Add RecyclerView in your layout file.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2. Create another layout file and define the template UI of the item that the RecyclerView is going to display. RecyclerView will populate each item that it holds with this layout.
item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView_alarm"
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/alarm" />
<TextView
android:id="#+id/textView_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#FF0000"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Time"
android:textColor="#android:color/background_light"
android:textSize="24sp" />
</LinearLayout>
3. Create a ViewHolder class that extends from RecyclerView.ViewHolder. View holder is a RecyclerView related concept. In short it works as a wrapper around the view of a single item and aids in binding new data to the view of the item. Create a bind() function inside view holder to make your life easier.
EDIT: I have updated the class by implementing the View.OnClickListener interface, modified the constructor to pass in the context from onCreateViewHolder() and adding a setItemPosition() just for the sake to pass the item position number from onBindViewHolder() all over to here so we can use this position number in our onClick() method of the interface
MyViewHolder.java [UPDATED]
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView textView;
private int itemPosition;
private Context mContext;
public MyViewHolder(#NonNull View itemView, Context context) {
super(itemView);
itemView.setOnClickListener(this);
mContext = context;
textView = itemView.findViewById(R.id.textView_Time);
}
void bind(String timeText)
{
textView.setText(timeText);
}
void setItemPosition(int position)
{
itemPosition = position;
}
#Override
public void onClick(View v) {
Toast.makeText(mContext, "You clicked item number: " + itemPosition , Toast.LENGTH_SHORT).show();
}
}
4. Create an Adapter class that extends from RecyclerView.Adapter. Adapter works as a bridge between the UI data and RecyclerView itself. An Adapter tells the RecyclerView what layout file to inflate and how many to inflate. RecyclerView job is to deal with how to inflate it on the UI.
EDIT : Just changed myViewHolder in onCreateViewHolder() to match the modified constructor of MyViewHolder. Added the call to setItemPosition() in the onBindViewHolder().
MyAdapter.java [UPDATED]
public class MyAdapter extends RecyclerView.Adapter {
List<String> timeIntervalList = new ArrayList<>();
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(view , parent.getContext());
return myViewHolder;
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
MyViewHolder viewHolder = (MyViewHolder) holder;
viewHolder.setItemPosition(position);
viewHolder.bind(timeIntervalList.get(position));
}
#Override
public int getItemCount() {
return timeIntervalList.size();
}
public void addItem (String timeText)
{
timeIntervalList.add(timeText);
notifyItemInserted(getItemCount());
}
}
In this adapter you will see two functions. OnCreateViewHolder() inflates the view using the template layout file for a single item and OnBindViewHolder() binds new data to the default values of the of the view just created. The data used for binding is stored in a list inside this Adapter called the timeIntervalList. This list will hold your time interval strings so they can be updated on the view.
5. Finally, use this RecyclerView where you want to use it. Like in your MainActivity.java. RecyclerView needs to be told in what fashion to display the items (e.g list , grid etc ) using a LayoutManager. LinearLayoutManager will display items either vertically or horizontally. You can see I am using your logic to increment time from string and adding new views to RecyclerView using the addItem() function of the MyAdapter class.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView myRecyclerView;
private MyAdapter myAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myRecyclerView = findViewById(R.id.recyclerView);
myAdapter = new MyAdapter();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this , LinearLayoutManager.HORIZONTAL, false);
myRecyclerView.setLayoutManager(linearLayoutManager);
myRecyclerView.setAdapter(myAdapter);
// This is how you will populate the recycler view
String START_TIME = "7:00";
String END_TIME = "22:00";
char first = START_TIME.charAt(0);
int StartTimeint = Integer.parseInt(String.valueOf(first));
int l;
for( l = StartTimeint; l<=22; l++){
// This is where new item are added to recyclerView.
myAdapter.addItem(l + ":00");
}
}
}
This is the final result.
Change your activity layout XML code as follows,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="#+id/llMain"
android:layout_height="match_parent"
tools:context=".SeatsPagewithDB.SeatsPage">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
...>
<LinearLayout
android:id="#+id/container"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
Move the textview and imageview to another XML file let's call it item_view.xml (you can name it whatever you wish). we are doing so because the root view of this file will be reused.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView11"
android:layout_width="150px"
android:layout_height="150px"
app:srcCompat="#drawable/seat"/>
<TextView
android:id="#+id/timeofseats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="7:00"
android:textColor="#fff"
android:textSize="20dp"/>
</LinearLayout>
Now make following changes in your Java file
LinearLayout container = findViewById(R.id.container); // or rootView.findViewById() for custom View and Fragment
char first = StartTime.charAt(0);
int StartTimeint = Integer.parseInt(String.valueOf(first));
for(int l = StartTimeint; l<=22; l++){
Log.d("SeatsPage", "Time is "+l);
View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_view, null);
TextView timeofseats = view.findViewById(R.id.timeofseats);
timeofseats.setText(Integer.toString(l));
container.addView(view);
}
I am attempting to create shared element transition between two Activities. This appears to work find between two layouts, each containing a single ImageView. However, I am having issues getting this transition to work with a ListView.
The issue is when the user taps on the first row, the transition will work as expected. However, when the second row is tapped, the origin of the transition appears to be the image of the first row as well!
I have created a simple list view with a custom row layout:
row_detailed.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Daft Punk"
android:id="#+id/primary_textview"
android:layout_gravity="center_horizontal"
android:layout_weight="0.07"
android:layout_alignTop="#+id/primary_imageview"
android:layout_toRightOf="#+id/primary_imageview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Random Access Memories"
android:id="#+id/textView4"
android:layout_gravity="center_horizontal"
android:layout_weight="0.07"
android:layout_alignBottom="#+id/primary_imageview"
android:layout_toRightOf="#+id/primary_imageview" />
<ImageView
android:layout_width="84dp"
android:layout_height="84dp"
android:id="#+id/primary_imageview"
android:src="#drawable/ram"
android:layout_weight="0.07" />
</RelativeLayout>
The layout for the secondary Activity, activity_transition_secondary.xml:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="legiocode.com.tapstrprototype.activity.TransitionSecondaryActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/secondary_imageview"
android:src="#drawable/ram"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
The Primary Activity, TransitionPrimaryActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition_primary);
ListView listView = (ListView)findViewById(R.id.listView2);
ArrayAdapter<String> adapter = new ArrayAdapter(this,
R.layout.row_detailed,
R.id.primary_textview,
items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String transitionName = getString(R.string.transition_image) + String.format("_%d", i);
ImageView imageView = (ImageView)findViewById(R.id.primary_imageview);
imageView.setTransitionName(transitionName);
Intent intent = new Intent(TransitionPrimaryActivity.this, TransitionSecondaryActivity.class);
intent.putExtra(TransitionSecondaryActivity.TRANSITION_NAME, transitionName);
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(TransitionPrimaryActivity.this,
imageView, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
ActivityCompat.startActivity(TransitionPrimaryActivity.this, intent, options.toBundle());
}
});
}
The Secondary Activity, TransitionSecondaryActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition_secondary);
String transitionName = getIntent().getStringExtra(TRANSITION_NAME);
ImageView imageView = (ImageView)findViewById(R.id.secondary_imageview);
imageView.setTransitionName(transitionName);
}
I have tried to implement the transition names dynamically, but that doesn't seem to make much of a difference. Am I setting up the transition correctly?
You have to access your actually clicked View (in this case parameter view) in
onItemClick(AdapterView<?> adapterView, View view, int i, long l)
With
ImageView imageView = (ImageView)findViewById(R.id.primary_imageview);
you always access the first element in the list.
PS: Put the transition names inside the xml. Makes it much more easy to read.
I have the following activity:
<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"
tools:context="es.xxx.xxx.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#CCFF0000"
android:id="#+id/lyNetworkError">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No hay conexión a internet"
android:textAlignment="center"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"/>
</RelativeLayout>
In its FrameLayout the app will load other fragments.
This is the onCreate code of activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Constants.setAppContext(this);
setContentView(R.layout.activity_main);
Log.d("LoadFragment", "1 "+ loadFragment);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit();
}
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filter);
fragmentManager = getSupportFragmentManager();
lyNetworkError = (LinearLayout) findViewById(R.id.lyNetworkError);
}
The problem is that LinearLayout (That contains TextView) doesn't show (is posible that fragment render over LinearLayout, because if I remove getSupportFragmentManager().beginTransaction().replace(R.id.container, new MainFragment()).commit(); the LinearLayout appears)
So, how can I show the LinarLayout over fragment (loaded inside FrameLayout)?
If the LinearLayout and your Fragments are displaying in the correct location on screen when each is shown individually, then you can simply reverse the order of of the FrameLayout and LinearLayout in your XML.
The problem is that RelativeLayout allows its children to overlap. The last item in the RelativeLayout will appear "above" or "on top" of other items in the layout. Since you haven't specified any layout constraints for your views, the RelativeLayout puts them both in the default position, which is the top left corner. Since your FrameLayout is set to fill the parent view's width and height, it will overlay everything else.
If you actually want the LinearLayout to appear above the FrameLayout, then you can use RelativeLayout's positioning properties (explained very well here) to position your views.
Specifically, you would be looking for something like this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/lyNetworkError"
android:id="#+id/container"/>
The android:layout_below attribute tells the FrameLayout that you want it to always be below the view with ID lyNetworkError (below as with text on a piece of paper, not in 3-dimensional space).
I've got this Layout:
ComposeView http://img845.imageshack.us/img845/2121/d6zp.png
The 2 borders (left,right )are filled by icons. When I touch one of these icons I access to other activity. The top black bar is a custom title bar.
The clear grey inside space is where I need to fit all activities that I've got on my app. So this layout would be something like a menu layout that would be static in all the activities.
This is the Layout xml:
menu_view.xml
<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"
tools:context="com.example.MenuView" >
<!-- Show top black custom title bar-->
<include
layout="#layout/custom_tittlebar" >
</include>
<!-- Button columns -->
<LinearLayout
android:id="#+id/lefthandmenu"
android:layout_width="85dip"
android:layout_height="match_parent"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:background="#drawable/border_cut" >
<ImageView
... />
...
</LinearLayout>
<LinearLayout
android:id="#+id/righthandmenu"
android:layout_width="85dip"
android:layout_height="match_parent"
android:layout_below="#id/title"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:background="#drawable/border_cut" >
<ImageView
... />
...
</LinearLayout>
<!-- Blank space which will contain other activities -->
<LinearLayout
android:id="#+id/activitycontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/righthandmenu"
android:layout_toRightOf="#id/lefthandmenu"
android:layout_below="#id/title"
android:orientation="vertical" >
</LinearLayout>
And this is the class where are defined all the icon's onClickListeners.
MenuView.java
public class MenuView extends RelativeLayout {
private final LayoutInflater inflater;
Context context;
public MenuViewActivity(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.menu_view, this, true);
((ImageView)this.findViewById(R.id.navButton)).setOnClickListener(launch_nav);
}
final OnClickListener launch_nav = new OnClickListener() {
#Override
public void onClick(View v) {
getContext().startActivity(new Intent(getContext(), Navigation.class));
}
};
Well, having this (I'm not sure if its all ok, maybe I'm doing something wrong with the inflate method or something like this), now the thing would be to define the other activitie's layouts to be inside this view. To do this, I write:
ExampleActivity.java
public class ExampleActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout inside_menu_view = (LinearLayout)findViewById(R.id.activitycontent);
View this_layout = getLayoutInflater().inflate(R.layout.main, inside_menu_view, true);
inside_menu_view.addView(this_layout);
But I'm getting a NullPointerException on this last line. So, something when inflating on this snippets must be wrong.
Hey use the following structure. put. include your common layout in each and every activity layout
<?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:orientation="vertical" >
<!-- Show top black custom title bar-->
<include
android:id="#+id/ll_top"
layout="#layout/custom_tittlebar"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</include>
<include
android:id="#+id/ll_left"
layout="#layout/custom_left"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
</include>
<include
android:id="#+id/ll_right"
layout="#layout/custom_right"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
</include>
<Button
android:id="#+id/btn_center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="center"
android:layout_toRightOf="#+id/ll_left"
android:layout_centerHorizontal="true"
android:layout_below="#+id/ll_top"
></Button>
</RelativeLayout>
You can have one main activity like BaseActivity that is extended by FragmentActivity. Base activity extends SlidingFragmentActivity and implements basic structure like menu etc. FragmentActivity onCreate method is :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fm = getSupportFragmentManager();
//This is main content that is switchable
mContent = new MainListActivity();
//Additionally you can define those two lines as fragments and add them as default on both sides :
sideFragments = new sideFragments(this);
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, mContent);
ft.replace(R.id.side_framgments, sideFragments);
ft.commit();
}
When you press some of those buttons from your menu(left and right border) you will change the fragment in middle of the screen with this function in FragmentActivity :
public void switchContent(Fragment fragment, String tag) {
mContent = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,fragment).addToBackStack(tag).commit();
}
Note R.id.content_frame is the XML that is switchable between those two lines (let say menus on both sides) and R.id.side_framgments are those two lines in between the main layout that is switchable.
I have enabled the built in zoom controls in my google maps application, however, it shows on my footer button panel:
I want the zoom controls to be one top of the footer button bar.
public class MinuteMapActivity extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// the methods on the map are initialised here - onCreate
zoomControls();
satelliteDisplay();
snapToMap();
}
// method for Zoomcontrols
private void zoomControls() {
LinearLayout zoomControls = (LinearLayout) findViewById(R.id.zoomControls);
MapView zoomLayout = (MapView) findViewById(R.id.MapView);
//zoomControls.addView(zoomLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
zoomLayout.setBuiltInZoomControls(true);
}
XML Layout:
?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"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="#+id/MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0zZsLcQS5Zeiqjbo1n8-nn2CqtxKIuTq2T6bskg"
/>
<!-- set zoom controls on map at the bottom -->
<LinearLayout
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
If I enable
//zoomControls.addView(zoomLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
it crashes.
Some assistance on how I can move the zoomcontrols above the bottom bar.
I think the reason it crashes is because you are trying to assign LinearLayout parameters to a layout inside a RelativeLayout, so you would have to use RelativeLayout.LayoutParams instead.
Also, I am a bit confused as to why you are using a LinearLayout for your zoom controls instead of the pre-defined View called ZoomControls. Perhaps it would save you a bit of time?
If you want to place the zoom controls above your bottom view use
<ZoomControls
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/buttonbar" />
assuming you call your ButtonBar view buttonbar.
May you have missed the two line of code in your
<com.google.android.maps.MapView.
so paste this two lines in it and you will got it. its working 100 percent.
android:enabled="true"
android:clickable="true"