I have a map activity, which also contains a navigation drawer layout with items in the drawer. I want to be able to click an item in the drawer, and the item i choose opens an activity. I tried using startActivity to call the class in a separate page, but it distorted my xml file in my emulator. I also tried updateFragment(); but it showed my new class as an error. would anyone know what i can do?
this is my MapActivity.java file
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap;
DrawerLayout drawerLayout;
ListView listView;
ActionBarDrawerToggle drawerToggle;
String[]items;
int selectedPosition=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
items=getResources().getStringArray(R.array.options);
drawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
listView=(ListView)findViewById(R.id.drawer_list);
ArrayAdapter<String>adapter=new ArrayAdapter<String>(MapsActivity.this,R.layout.drawer_list_item,items);
listView.setAdapter(adapter);
drawerToggle=new ActionBarDrawerToggle(MapsActivity.this,drawerLayout,R.drawable.images,R.string.drawer_open,R.string.drawer_close){
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(drawerToggle);
// getActionBar().setHomeButtonEnabled(false);
// getActionBar().setDisplayHomeAsUpEnabled(false);
// getActionBar().setDisplayShowTitleEnabled(false);
// getActionBar().setDisplayShowHomeEnabled(false);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedPosition = position;
if (selectedPosition==2){
startActivity(new Intent(MapsActivity.this, MenuActivity.class);
}
// updateFragment();
drawerLayout.closeDrawer(listView);
}
});
// selectedPosition=0;
// updateFragment();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
private void updateFragment() {
FragmentManager fragmentManager=getFragmentManager();
WebViewFragment rFragment=new WebViewFragment();
Bundle data=new Bundle();
data.putString("title",items[selectedPosition]);
rFragment.setArguments(data);
FragmentTransaction ft=fragmentManager.beginTransaction();
ft.replace(R.id.content_frame,rFragment);
ft.commit();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
}
My MenuActivity.xml
<FrameLayout 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.xxxxxx.qdoba.MenuFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#drawable/woodcrop">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="MENU"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="60dp"
android:textColor="#ff912424" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginTop="100dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView3"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView4"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView5"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView6"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView7"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView8"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView9"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView10"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView11"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView12"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
this is how it looks in the preview;
this is how it looks on the emulator :(
one image:
It happens because you are using layout_width="100dp" for every image view and 20dp of margin, so the final width of your layout bigger than screen width of device. You can see it if you change preview from Nexus 6 to Nexus One, for example.
You can use layout_weight parameter for every image or TableLayout with 3 columns, or you may try to use GridLayout.
Try this, for example.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
</LinearLayout>
Or with same effect
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
</TableRow>
//your other rows
</TableLayout>
Related
I have button on my activity that show up on the fragment and only the button that show up , i did search about it and find out its a rendering issue but the answers didn't worked for me, here how it looks.
Fragment
Activity
is there any chance that the issue code be from the margin of the button
Fragment.java
public class Smsar extends Fragment {
public Smsar() {
// Required empty public constructor
}
View root;
Button mSmsar,mFinder;
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
root= inflater.inflate(R.layout.fragment_smsar, container, false);
mSmsar=(Button)root.findViewById(R.id.smsar);
mFinder=(Button)root.findViewById(R.id.finder);
mSmsar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
mFinder.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Open Discover.
}
});
return root;
}
}
Fragment 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background_difference"
tools:context=".Smsar">
<!-- TODO: Update blank fragment layout -->
<Button
android:id="#+id/smsar"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Smsar ?"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="18sp"
android:typeface="normal" />
<Button
android:id="#+id/finder"
android:layout_width="204dp"
android:layout_height="63dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="138dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Want Apartment ?"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</RelativeLayout>
Activity 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
tools:context=".MainActivity"
android:id="#+id/mainView"
>
<ImageView
android:id="#+id/logo"
android:layout_width="162dp"
android:layout_height="196dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:adjustViewBounds="true"
android:maxHeight="64dp"
android:maxWidth="64dp"
app:srcCompat="#drawable/logo" />
<Button
android:id="#+id/logIn"
android:layout_width="218dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/userName"
android:layout_alignParentBottom="true"
android:layout_marginEnd="31dp"
android:layout_marginBottom="113dp"
android:background="#color/buttons"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:onClick="logIN"
android:text="Login"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="22sp" />
<EditText
android:id="#+id/userName"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ems="10"
android:fontFamily="#font/catamaran"
android:hint="UserName"
android:inputType="textPersonName"
android:text="" />
<EditText
android:id="#+id/password"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_centerHorizontal="true"
android:fontFamily="#font/catamaran"
android:hint="Password"
android:inputType="textPassword" />
<TextView
android:id="#+id/_new"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-35dp"
android:layout_marginBottom="0dp"
android:layout_toStartOf="#+id/sginUp"
android:fontFamily="#font/catamaran"
android:text="New ? Start Now By"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="#+id/sginUp"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginBottom="0dp"
android:layout_centerHorizontal="true"
android:layout_toEndOf="#id/mError"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:text="SginUp"
android:textAlignment="center"
android:textColor="#color/links"
android:textSize="18sp" />
<TextView
android:id="#+id/mError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="82dp"
android:textColor="#android:color/holo_red_dark"
android:visibility="invisible"
android:text="mError" />
</RelativeLayout>
Activity.Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_login =(Button)findViewById(R.id.logIn);
pref = getSharedPreferences("user_details", MODE_PRIVATE);
if(pref.contains("username")&&pref.contains("password"))
success();
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(null);
ft.replace(R.id.mainView, mFrag);
ft.commit();
imageView=(ImageView)findViewById(R.id.logo);
mDBHelper =new DBHelper(this);
mError=(TextView)findViewById(R.id.mError);
//Define the variables
userNameEdit=(EditText)findViewById(R.id.userName);
passwordEdit=(EditText)findViewById(R.id.password);
_signUp=(TextView)findViewById(R.id.sginUp);
//End
_signUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent=new Intent(MainActivity.this,Signup.class);
startActivity(intent);
}
});
}
I solve it by surround the button with LinearLayout
<LinearLayout
android:id="#+id/buttonContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/password"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
<Button
android:id="#+id/logIn"
android:layout_width="186dp"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:background="#drawable/btn_rounded"
android:minWidth="200dp"
android:onClick="logIN"
android:text="#string/title_login"
android:textAllCaps="false"
android:textColor="#color/ms_white"
android:textSize="18sp" />
</LinearLayout>
Now i have a possible hint what's going on Scrollview/ListView is considering the real Height and width of device to render layout. However in easy dialog box we can display it at (below/left/right/up) to any view. As Scrollview/ListView is considering whole device height so it isn't allowing scroll(Not needed when child layout is smaller that parent height).
I have a scroll view layout which i am inflating in a view to pass to a third party dialogue box EasyDialog. This is how i my Scroll View layout looks like.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/menuAboutUs"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/about_us_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:textColor="#color/darkBlueColor"
android:text="About Us"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout
android:id="#+id/menuAboutApp"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/about_app_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:text="About App"
android:textColor="#color/darkBlueColor"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout
android:id="#+id/menuHistory"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/history_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:text="History"
android:textColor="#color/darkBlueColor"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout
android:id="#+id/menuNutritionChart"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/nutrition_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:text="Nutrition Chart"
android:textColor="#color/darkBlueColor"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout
android:id="#+id/menuTvCommercial"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/tvc_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:text="TV Commercials"
android:textColor="#color/darkBlueColor"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="#color/colorPrimary">
</View>
<LinearLayout
android:id="#+id/menuJingles"
android:layout_width="200dp"
android:layout_height="40dp"
android:gravity="left"
android:orientation="horizontal">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="#android:color/transparent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/jingles_ico" />
<TextView
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="left|bottom"
android:padding="5dp"
android:text="Jingles"
android:textColor="#color/darkBlueColor"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</ScrollView>
EasyDialog show complete layout view when I am in Portrait screen orientation mode. However when I change my phone orientation to landscape mode. Scroll view cut off child layout and doesn't scroll over complete child layout.This is how i am inflating my view for Easy Dialogue.
Here is how i am inflating easy dialogue
private void LeftMenu() {
View view = getLayoutInflater().inflate(R.layout.layout_left_menu_main, null);
menuAboutUs = (LinearLayout) view.findViewById(R.id.menuAboutUs);
menuAboutUs.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,AboutUsActivity.class);
intent.putExtra("moduleName","Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
menuAboutApp = (LinearLayout) view.findViewById(R.id.menuAboutApp);
menuAboutApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,AboutAppActivity.class);
intent.putExtra("moduleName","Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
menuHistory = (LinearLayout) view.findViewById(R.id.menuHistory);
menuHistory.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,HistoryActivity.class);
intent.putExtra("moduleName","Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
menuNutritionChart = (LinearLayout) view.findViewById(R.id.menuNutritionChart);
menuNutritionChart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,NutritionChartActivity.class);
intent.putExtra("moduleName","Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
menuTvCommercials = (LinearLayout) view.findViewById(R.id.menuTvCommercial);
menuTvCommercials.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,TvCommercialActivity.class);
intent.putExtra("moduleName","Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
menuJingles = (LinearLayout) view.findViewById(R.id.menuJingles);
menuJingles.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, JinglesActivity.class);
intent.putExtra("moduleName", "Main");
startActivity(intent);
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
EasyDialog easyDialog = new EasyDialog(MainActivity.this)
.setLayout(view)
.setBackgroundColor(MainActivity.this.getResources().getColor(R.color.whiteColor))
// .setLocation(new location[])//point in screen
.setLocationByAttachedView(ibLeftTitle)
.setGravity(EasyDialog.GRAVITY_BOTTOM)
.setAnimationTranslationShow(EasyDialog.DIRECTION_X, 1000, -600, 100, -50, 50, 0)
.setAnimationAlphaShow(1000, 0.3f, 1.0f)
.setAnimationTranslationDismiss(EasyDialog.DIRECTION_X, 500, -50, 800)
.setAnimationAlphaDismiss(500, 1.0f, 0.0f)
.setTouchOutsideDismiss(true)
.setMatchParent(false)
.setMarginLeftAndRight(24, 24)
//.setOutsideColor(MainActivity.this.getResources().getColor(R.color.overlay))
.show();
}
My Content is less than actual physical size of device but location at which i display easy dialog plus my content exceeding the height of physical display size of screen in landscape mode.
I am working in project that contain framelayout display fragments by navigation button next , back and I provide it method below in my code till now every thing works great
here is why I am here , I need make the same function done with navigation button done with swipe button , I add viewpager and pass all fragment to adapter but it give me different view overlapping
Fragment mFragmentsList[] = new Fragment[]{new Slide2Frag() , .... new Slide23Frag()};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here is what I need to add viewpager
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentsList);
mViewPager.setAdapter(adapter);
DisplayFragment(count);
}
// display fragment method
private void DisplayFragment(int display) {
Fragment fragment = null;
switch (display) {
case 2:
fragment = new Slide2Frag();
break;
}
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
mTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
mTransaction.replace(R.id.container, fragment).commit();
}
private void NextMethod() {
if (count < 23) {
count++;
} else {
count = 2;
}
DisplayFragment(count);
}
private void backMethod() {
if (count > 2) {
count--;
} else {
count = 23;
}
DisplayFragment(count);
}
my xml code
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/headerlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/home_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:layout_marginEnd="219dp"
android:layout_marginRight="219dp"
android:adjustViewBounds="true"
android:background="#drawable/home" />
<ImageView
android:id="#+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:adjustViewBounds="true"
android:background="#drawable/close" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="true"
android:background="#drawable/aciloc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_below="#+id/home_btn"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:adjustViewBounds="true"
android:background="#drawable/leadingppi"
android:scaleType="centerInside" />
</RelativeLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_above="#+id/footer_layout"
android:layout_below="#+id/headerlayout" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:weightSum="6">
<ImageButton
android:id="#+id/left_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/left_back"
android:scaleType="centerInside" />
<Button
android:id="#+id/ac20"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 20mg" />
<Button
android:id="#+id/ac40"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 40mg" />
<Button
android:id="#+id/profile"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="PROFILE" />
<Button
android:id="#+id/indications"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="INDICATIONS & DOSAGE" />
<Button
android:id="#+id/pack"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="UNIQUE PACK" />
<ImageButton
android:id="#+id/right_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/right_back"
android:scaleType="centerInside"
android:textColor="#color/text_color"/>
</LinearLayout>
</RelativeLayout>
here is image explain
I have created a recyclerview usin cardview and added button in each of the items of the recyclerview. I have already integrated the button click event . Now, when I click the button of one of the recyclerview item it responds normally and the button of other items responds too at the same time as if they are also clicked.what is the problem? how can it be solved?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="95dp"
android:orientation="horizontal"
android:weightSum="3">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:cardCornerRadius="1dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true">
<ImageView
android:id="#+id/icon_vendor1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:padding="0dp"
android:scaleType="fitXY"
android:src="#drawable/ic_direction" />
<TextView
android:id="#+id/vendorName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/icon_vendor1"
android:text="Kozzaja Infotech Pvt Ltd"
android:textSize="20sp" />
<RatingBar
android:id="#+id/rating"
style="#style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/vendorName1"
android:layout_marginTop="4dp"
android:layout_toEndOf="#+id/imageView2"
android:layout_toRightOf="#+id/icon_vendor1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/vendorName1"
android:layout_marginBottom="3dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="#+id/button4"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:background="#drawable/circle_button"
android:padding="10dp"
android:src="#drawable/ic_call_black_36dp" />
<ImageButton
android:id="#+id/button3"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:background="#drawable/circle_button"
android:padding="20dp"
android:src="#drawable/ic_messenger_outline_black_36dp" />
<ImageButton
android:id="#+id/button2"
android:layout_width="38dp"
android:layout_height="match_parent"
android:background="#drawable/circle_button"
android:src="#drawable/ic_directions_black_24dp" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/layout"
android:background="#drawable/circle_button"
android:tag="off"
android:text="+"
android:textSize="30sp" />
<View
android:layout_width="11dp"
android:layout_height="38dp"
android:background="#ffffff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
This is my adapter's code.
#Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.title.setText(workers.get(position).getName());
holder.rating.setRating(workers.get(position).getRatings());
Picasso.with(context).load(workers.get(position).getImageLogo()).fit().into(holder.imageView);
holder.plus.setTag("off");
holder.plus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/// button click event
if (holder.plus.getTag().toString().equals("off")) {
holder.plus.setTag("on");
holder.plus.setText("-");
//show the options button using animation
holder.layout.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_to_right));
holder.layout.setVisibility(View.VISIBLE);
} else if (holder.plus.getTag().toString().equals("on")) {
holder.plus.setTag("off");
holder.plus.setText("+");
//hide the options button using animation
holder.layout.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_to_left));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//disappear the button after 500ms
holder.layout.setVisibility(View.GONE);
}
}, 500);
}
}
});
}
how to set tab bar at specific position of layout as shown in image....
in xml layout i set like three relative view one after another and tab host i put in third layout and also there is second layout is in proper position in view but problem with tab layout only.....
now this is xml file.....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#drawable/userprofile_bg" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:src="#drawable/novak_djokovic_medium" />
<TextView
android:id="#+id/se_1_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="NAME" />
<TextView
android:id="#+id/se_1_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/se_1_name"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text=",MALE" />
<TextView
android:id="#+id/se_1_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/se_1_name"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/se_1_sex"
android:text="18" />
<TextView
android:id="#+id/se_1_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/se_1_sex"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="UK" />
<TextView
android:id="#+id/se_1_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/se_1_sex"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/se_1_country"
android:paddingRight="5dp"
android:text="LONDON" />
<ImageView
android:id="#+id/se_1_bgphoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/bgphoto32x32" />
<ImageView
android:id="#+id/se_1_userphoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/se_1_bgphoto"
android:background="#drawable/userphoto32x32" />
<ImageView
android:id="#+id/se_1_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/se_1_userphoto"
android:background="#drawable/edit32x32" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="12" >
<RelativeLayout
android:id="#+id/rl11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" >
<TextView
android:id="#+id/we"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/we"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" >
<TextView
android:id="#+id/we"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/we"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" >
<TextView
android:id="#+id/we"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/we"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="12323" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" >
<TextView
android:id="#+id/we"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/we"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="123" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl112"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl113"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl114"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" >
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/s_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
</LinearLayout>
this is class file...
public class settings extends FragmentActivity implements ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "Top Rated", "Games", "Movies" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings1);
// Initilization
viewPager = (ViewPager) findViewById(R.id.s_pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
#Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
#Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
}
you need to position this view inside the parent view
<RelativeLayout
android:id="#+id/rl3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/s_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
you can do define a parent relative layout which will occupy the half screen and than you can align the above layout as the layout_below="#+id/define your above id here "