TransitionManager scene animation behavior with root layout - transition

I'm testing out the Android Kit Kat transition feature. When the transition happens, the margins of the root layout are getting padded. I find this behavior strange.
The source
public class MainActivity extends ActionBarActivity {
Button btn;
TextView txt;
#TargetApi(Build.VERSION_CODES.KITKAT)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView)findViewById(R.id.text);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ViewGroup root = (ViewGroup)findViewById(R.id.root);
Scene scene = Scene.getSceneForLayout(root, R.layout.activity_main2, MainActivity.this);
TransitionManager.go(scene);
}
});
}
...
}
activity_main.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"
android:id="#+id/root"
tools:context="com.sebouh00.test.scenes.MainActivity">
<Button android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:layout_marginBottom="12dp"/>
<TextView
android:id="#+id/text"
android:layout_below="#id/btn"
android:text="#string/hello_world"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="18dp"/>
</RelativeLayout>
activity_main2.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"
android:id="#+id/root"
tools:context="com.sebouh00.test.scenes.MainActivity">
<Button android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:layout_marginBottom="12dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/btn"
android:id="#+id/img"
android:src="#drawable/flag"
android:layout_marginBottom="12dp"/>
<TextView
android:id="#+id/text"
android:layout_below="#id/img"
android:text="#string/hello_world"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="18dp"/>
</RelativeLayout>
Results in this unless I remove the paddings from activity_main2.xml
Any ideas why?

It's because the View produced by inflating activity_main2 gets inserted into the Scene's root, i.e. your R.id.root RelativeLayout, so the padding from R.id.root is still applied.

Related

Customised InfoWindow of Google Map does not render elevation shadow in Android

I'm using InfoWindow to render any information for marker.
In Android, we can define shadow with elevation.
But the shadow defined by elevation is not rendered for InfoWindow.
The layout of infoWindow is like this
<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="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:elevation="4dp"
>
<TextView
android:id="#+id/main_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="14sp"
android:textStyle="bold"
tools:text="main text"
/>
<TextView
android:id="#+id/sub_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/main_text"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="11sp"
tools:text="sub text"/>
</RelativeLayout>
Shape is like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="500dp"/>
<solid android:color="#color/white"/>
</shape>
Code snippet is like this
googleMap?.setInfoWindowAdapter(object: GoogleMap.InfoWindowAdapter {
override fun getInfoContents(marker: Marker?): View? {
return null
}
override fun getInfoWindow(marker: Marker?): View? {
return layoutInflater.inflate(R.layout.map_info_window, null)
}
})

error while spec.setContent(Intent) on tabSpace

There is an error while i am putting Intent as spec.setContent(Intent); on tabSpace,and it works fine if i put a layout on spec.setContent(tab1);
And following is the error:-
did you forget to call 'public void setup(localactivitymanager
activitygroup)
Here is the class:-
public class test extends AppCompatActivity {
Point size;
RelativeLayout r1;
CallbackManager callbackManager;
Context context;
TabHost.TabSpec spec_signin,spec_signup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
context = getApplicationContext();
Display display = getWindowManager().getDefaultDisplay();
size = new Point();
display.getSize(size);
Bitmap bmp = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(),R.drawable.accont_bannre),size.x,size.y,true);
Drawable dr = new BitmapDrawable(bmp);
r1 = (RelativeLayout)findViewById(R.id.r1);
r1.setBackgroundDrawable(dr);
TabHost host = (TabHost)this.findViewById(R.id.tabhost);
host.setup();
//Tab 1
spec_signin = host.newTabSpec("SIGNIN");
Intent songsIntent = new Intent(this, NotificationActivity.class);
spec_signin.setContent(songsIntent);
spec_signin.setIndicator("SIGN IN", getResources().getDrawable(R.drawable.active_arrow));
// spec_signin.setIndicator("SIGNIN");
host.addTab(spec_signin);
//Tab 2
spec_signup = host.newTabSpec("SIGNUP");
Intent Intent = new Intent(this, NotificationActivity.class);
spec_signup.setContent(Intent);
spec_signup.setIndicator("SIGN UP", getResources().getDrawable(R.drawable.active_arrow));
// spec_signup.setIndicator("SIGNUP");
host.addTab(spec_signup);
}//oncreate ends
}
and the XML:-<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabHost
android:id="#+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/r2">
<RelativeLayout
android:id="#+id/r1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="270dp">
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_above="#+id/tabs"
android:id="#+id/v1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ccc7c7"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<FrameLayout
android:background="#dede"
android:layout_below="#+id/r1"
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
`
i have added following lines and it running.
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
host.setup(mLocalActivityManager);

list view on relative layout didn't show

activity_sms.xml
<?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"
>
<ListView
android:id="#+id/SMSList"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="10dp"
/>
</RelativeLayout>
code on SMSActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
code on fragment_1.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_sms, container, false);
return rootView;
I tried to make a program to read SMS from inbox and show it on a ListView. It works when SMSActivity is the only activity there
Now, I use MainActivity.java instead of SMSActivity.java as Main Activity.
My goal is to invoke SMSActivity.java using fragment.
If anyone can help me it would be nice :)
What exactly you want to show in your layout?For example you have some items like this
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/list_item_title"
android:text="#string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/list_item_details"
android:text="#string/description"
android:paddingTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
In ths case you can set the value for this items in your adapter
#Override
public View getView (int position,View convertView,ViewGroup parent){
View view = LayoutInflater.from(context).inflate(R.layout.linear_big_list_item, parent, false);
TextView nameOfItem = (TextView)convertView.findViewById(R.id.list_item_title);
TextView descriptionOfItem = (TextView)convertView.findViewById(R.id.list_item_details);
return view;
}

How to work with tabhost,tabwidget and framelayout?

I am using this code
package com.example.tabs;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Sími");
spec1.setContent(R.id.Sími);
spec1.setIndicator("Sími");
TabSpec spec2=tabHost.newTabSpec("Sms");
spec2.setIndicator("Sms");
spec2.setContent(R.id.Sms);
TabSpec spec3=tabHost.newTabSpec("Net");
spec3.setIndicator("Net");
spec3.setContent(R.id.Net);
TabSpec spec4=tabHost.newTabSpec("Greina");
spec4.setIndicator("Greina");
spec4.setContent(R.id.Greina);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.addTab(spec4);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
with this xml file
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/Sími"
android:layout_width="fill_parent"
android:layout_height="340dp"
android:orientation="vertical"
android:paddingTop="60px" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/Sms"
android:orientation="vertical"
android:paddingTop="60px"
>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/Net"
android:orientation="vertical"
android:paddingTop="60px"
>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/Greina"
android:orientation="vertical"
android:paddingTop="60px"
>
</LinearLayout>
</FrameLayout>
</TabHost>
I am new to android eclipse. I made 4 tabs(linearlayout) inside this tabview. But it is difficult to set the location on a button in one tab. How can i work with this 4 types of tabs like i am working with 4 xml files, is that possible ? How can i make the tabwidget smaller without the text not going away? , i hope this makes sense.

Get value from custom dialog edittext in android

I my project i have a text view and button on my screen. On button click event i show custom dialog box (Dialog box content Edit text and a button). I put some data in dialog box edit text and click dialog box save button.
Now i want to show value of dialog edit text on screen text view on button click. How can i do this....
holder.list1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final TextView tv=(TextView)v.findViewById(R.id.textView3);
final Dialog dialog = new Dialog(activity);
dialog.setContentView(R.layout.customdailogfroaddmilk);
dialog.setTitle("Account");
// set the custom dialog components - text, image and button
final EditText text = (EditText) dialog.findViewById(R.id.editText1);
text.setText(tv.getText().toString());
Button save = (Button) dialog.findViewById(R.id.button1);
Button cancle = (Button) dialog.findViewById(R.id.button2);
save.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
tv.setText(text.getText().toString());
}
});
cancle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
on button(save) click event edittext(save) value not set in textview(tv)
?????.....
Create a layout in your layout folder and provide it as the View to a Dialog Object.
And for the example shown below, you need to have a TextView, a Button and EditText in that layout.
final Dialog dialog = new Dialog(context,
android.R.style.Theme_Translucent_NoTitleBar);
Window window = dialog.getWindow();
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.xmlfile);
Button ok = (Button) dialog.findViewById(R.id.alert_ok_button);
TextView alert_title = (TextView ) dialog.findViewById(R.id.alert_title);
final EditText shelf_name_edit=(EditText)dialog.findViewById(R.id.shelf_name_edit_area);
alert_title.setText(title);
alert_title.setTextSize(20);
ok.setText("OK");
ok.setTextSize(20);
ok.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.cancel();
Log.i("EditText Value",shelf_name_edit.getEditableText().toString());
}
});
dialog.show();
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/ClkBtn"
android:text="Click Me"></Button>
</RelativeLayout>
mydialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff" android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView android:id="#+id/Tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15px"
android:textColor="#6aa4cc"
android:text="Friendcaster for Facebook"
android:padding="10dip"
/>
<TextView android:id="#+id/Tv2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="14px"
android:textColor="#android:color/black"
android:layout_below="#+id/Tv1"
android:textStyle="bold"
android:text="A , B , C , D and or 5 friend like your status "
android:padding="10dip"
/>
<View android:layout_height="15dip" android:layout_width="fill_parent"/>
<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent"
android:orientation="horizontal" android:background="#d6d6d6"
android:layout_weight="3"
>
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="left"
android:id="#+id/ll"
android:layout_weight="1" android:padding="5dip"
>
<ImageView android:src="#drawable/video"
android:layout_height="30dip" android:layout_width="30dip" android:layout_gravity="center_vertical|center_horizontal"
/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="view" android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#0388e5"
/>
</LinearLayout>
<View android:layout_height="match_parent" android:layout_width="1dip" android:background="#android:color/darker_gray"/>
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_weight="1" android:padding="5dip"
>
<ImageView android:src="#drawable/chat"
android:layout_height="30dip" android:layout_width="30dip" android:layout_gravity="center_vertical|center_horizontal"
/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Reply" android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#0388e5"
/>
</LinearLayout>
<View android:layout_height="match_parent" android:layout_width="1dip" android:background="#android:color/darker_gray"/>
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_weight="1" android:padding="5dip"
android:gravity="right"
>
<ImageView android:src="#drawable/cancel"
android:layout_height="30dip" android:layout_width="30dip" android:layout_gravity="center_vertical|center_horizontal"
/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Zip" android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#0388e5"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
main.java
package com.example.cusmizepopup;
import android.os.Bundle;
import android.os.Message;
import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends Activity {
Dialog myDialog;
Button myButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton = (Button) findViewById(R.id.ClkBtn);
myButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
myDialog = new Dialog(MainActivity.this);
myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
myDialog.setContentView(R.layout.mydialog);
//myDialog.setTitle("My Dialog");
myDialog.setCancelable(true);
//myDialog.setCancelable(true);
//myDialog.setCancelMessage("Are you Sure ? ")
LinearLayout button = (LinearLayout) myDialog.findViewById(R.id.ll);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
//myDialog.dismiss();
Toast.makeText(getApplicationContext(), "hi", Toast.LENGTH_LONG).show();
}
});
myDialog.unregisterForContextMenu(myButton);
myDialog.show();
}
});
}
}