I'm trying to integrate some Facebook stuff (posting on your own "wall") in my TabView.
The problem I'm facing is that while I do not have the Facebook app installed, I get a Webview showing the login and posting. It shows nicely, except for the buttons at the bottom. If I scroll down to see the buttons, they just go a little bit lower.
The layout of the tab:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="40dip">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Test_Facebook_Layout">
<Button android:id="#+id/facebookButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login to facebook"/>
</LinearLayout>
</ScrollView>
Got all the code (except the parts I changed and will post below) from here.
public void onClick(View v)
{
if (v == facebookButton)
{
facebookClient = new Facebook("myAwesomeKey");
facebookClient.authorize(this, new String[] {"publish_stream", "read_stream", "offline_access"}, this);
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//https://stackoverflow.com/questions/2953146/android-java-post-simple-text-to-facebook-wall
setContentView(R.layout.detailsfacebooktab);
facebookButton = (Button)this.findViewById(R.id.facebookButton);
facebookButton.setOnClickListener(this);
}
What would be nice is either a) Getting the WebView to not fill my screen or b) Keep the buttons from scrolling away.
EDIT: Because a picture says more than a thousend words, here's three thousand words.
(if it isn't clear, Picture 1 shows the initial view, Picture 2 shows my scrolling down, Picture 3 shows the buttons getting away)
For the moment I found a c) Getting the buttons a bit higher.
The problem is the user can still scroll the WebView, enlarging the View and scrolling the buttons back down again.
I edited these values in com.facebook.android.fbDialog.java to show the buttons a bit more.
static final float[] DIMENSIONS_LANDSCAPE = {440, 260};
static final float[] DIMENSIONS_PORTRAIT = {280, 380};
Because this does not completely solve my problem, I've edited my OP instead of posting my own "answer".
Thank you,
iarwain01
Related
I am using an ImageView as a NEXT button in my Android app which is responsible for loading the next page of results into the current activity. However, despite that I bind a click listener to it, I cannot seem to capture click events on this ImageView. Here is the XML:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:gravity="left"
android:orientation="horizontal">
<ImageView
android:id="#+id/listBackIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_icon"/>
<TextView
android:id="#+id/listBackLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prev"
android:textSize="16dip"/>
</LinearLayout>
And here is the relevant Java code:
ImageView forwardIconView = (ImageView)findViewById(R.id.listBackIcon);
// not sure if necessary; doesn't fix it anyway
forwardIconView.setClickable(true);
forwardIconView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
++pageNumber;
try {
params.put("page", pageNumber);
} catch (JSONException e) {
// do something
}
ConnectionTask task = new ConnectionTask();
task.execute(new String[0]);
}
});
I spent about an hour researching this on Stack Overflow. I found a few places which claimed that ImageView could directly be made clickable, but most things recommended workarounds using other types of widgets.
Does anything about my layout/code stand out as being a culprit for this behavior?
Update:
I also tried binding a click listener to the TextView at the same level as the ImageView and this too failed to capture clicks. So now I am suspecting that the views are being masked by something. Perhaps something is capturing the clicks instead of the views.
I would set it up like this:
private ImageView nextButton;
nextButton = (ImageView)view.findViewById(R.id.back_button);
Util.loadImage(getActivity(),R.drawable.some_image,nextButton); //Here i would load the image, but i see you do it in XML.
nextButton.setOnClickListener(nextButtonListener);
nextButton.setEnabled(true);
View.OnClickListener nextButtonListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v(TAG, "ImageView has been clicked. do something.");
}
};
This works for me.
Why not use android:drawableLeft attribute for the textview instead of using imageView​ and textview both in a linearlayout .
<ImageView
android:id="#+id/listBackIcon"
...
android:clickable="true"
Or you can try overriding onTouchListener with ACTION_DOWN event filter, not onClickListener. Also check for parrents with android:clickable="false", they could block childs for click events.
What seemed to work for me was the accepted answer from this SO question, which suggests adding the following the every child element of the LinearLayout which I pasted in my question:
android:duplicateParentState="true"
I don't know exactly what was happening, but it appears the click events were not making it down to the TextView and ImageView. Strangely, the click events were reaching a Button, when I added one for debugging purposes. If someone has more insight into what actually happened, leave a comment and this answer can be updated.
I'm trying to make a game like a "click & kill" and I'm trying to make a health bar for the character to kill.
I'm using a simple image (a red rectangle) and I would like to reduce the health bar after one click. What I tryed works but the problem is not just the with decrease, the height too. So the result is really horrible. To begin, this is my XML (I only show one for example):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00"
android:id="#+id/hole4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/healthBar4"
android:src="#drawable/health_bar"/>
</RelativeLayout>
So here nothing bad (I think) I leave android:adjustViewBounds="true" because I thought the problem came from here.
Next is my Activity :
final int healthBarHeightInitial = healthBar4.getLayoutParams().height;
final int healthBarWidthInitial = healthBar4.getLayoutParams().width;
healthBar4.requestLayout();
//ivHole4 is my ImageView I get the click to leave some life to the character
ivHole4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//If character die (works great).
if(choixAction.ChoixAction(CharaHole4,outil)){
Log.d("Perso","Character is die");
mAvancement +=1;
ivHole4.setImageResource(0);
CharaHole4 = null;
placeChara.setHole4(true);
healthBar4.setVisibility(View.GONE);
healthBar4.getLayoutParams().height = healthBarHeightInitial;
healthBar4.getLayoutParams().width = healthWidthInitial;
}
//if character don't die (here is the problem !)
else {
healthBar4.getLayoutParams().width = healthBar4.getWidth()/2; //This is works great
healthBar4.getLayoutParams().height = healthBarHeightInitial; //This is do nothing, the height is /2 too.
healthBar4.requestLayout();
}
}
});
I hope someone know how to change the image size not proportionally.
Thank's advance.
Your ImageView in the XML Layout needs to set the scale type to fitXY to allow it to expand without keeping proportions.
android:scaleType="fitXY"
Use Picasso Library and set Crop Center.
I have got one simple problem, my app contains 52 buttons but i cant display all buttons. I need suggest have can i solve this trouble the best as I can.
At the moment i have buttons like that:
http://prntscr.com/482kjw
but this solve is untransparent and i want one button make two functionaly one on click and second on long clik or something that, but i havent got idea how..
and now my question is: I need recommendations for the solution of my problem or some tutorial how to display two images on one button, Gridview.
you can make a layout of two images in one on a linearLayout with orientation:Horizontal or
To add two pics on one button, try this
android:drawableEnd="#drawable/ic_action_done1"
android:drawableTop="#drawable/ic_action_done2"
and so forth.. this puts two images-(#drawable/ic_action_done1 & #drawable/ic_action_done2)- on one button
and speaking of the functionality of the buttons, from my understanding to your question, you need a click function and a long press function, well you can use one button for to achieve these..
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
button.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
return false;
}
});
maybe it might help you.
SAMPLE OR TUTORIAL ON WHAT YOU ASKED
The name is button_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<Button
android:id="#+id/registerButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="8dp"
android:drawableLeft="#drawable/checkmark"
android:drawableRight="#drawable/ic_launcher"
android:text="#string/register"
android:textColor="#ffffff"
android:textSize="22sp" />
button_layout is the xml_file you will inflate..in the link you gave me the button_xml was written programatically in the baseAdapter which was
imageView imageView;
imageView = new ImageView(mContext);
you can also do yours programmatically in this way
Button button = (Button)getLayoutInflater().inflate(R.layout.button_layout, null);
it seems you are new in android. so check these sites, it might give you a lucid idea of what i mean..
http://www.learn2crack.com/2014/01/android-custom-gridview.html
http://www.mkyong.com/android/android-gridview-example/
http://www.tutorialspoint.com/android/android_grid_view.htm
http://www.androidhub4you.com/2013/07/custom-grid-view-example-in-android.html
http://androidexample.com/Custom_Grid_Layout_-_Android_Example/index.php?view=article_discription&aid=76&aaid=100
http://javatechig.com/android/android-gridview-example-building-image-gallery-in-android
I am taking reference from TextJustify-Android. I am implementing option 2 in above link. When I run my app on emulator text appears one word in one line, next word in next line and so on. I dont know whats wrong in my code. Please help me. Thanks.
Activity class code-
textView1 = (TextView) findViewById (R.id.textView1);
textView1.setMovementMethod(new ScrollingMovementMethod());
textView1.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener()
{
boolean isJustified = false;
#Override
public boolean onPreDraw()
{
if(!isJustified)
{
TextJustifyUtils.run(textView1,0);
isJustified = true;
}
return true;
}
});
Xml code-
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:text="#string/his"
android:textColor="#FFFFFF"/>
</LinearLayout>
And I am implementing TextJustifyUtils class in my app as suggested in above link.
I have made one change In that link given TextJustifyUtils.run(textView1); and In my code eclipse suggest me to change in TextJustifyUtils.run(textView1,0);. Is anything wrong with this?
Update:
In TextJustifyUtils I change public static void justify(TextView textView) into public static void run(TextView textView) as commented by the author there and TextJustifyUtils.run(textView1,0); into TextJustifyUtils.run(textView1); in Activity class. But the output is same as I type in my textView i.e text without justification.
If some one following the above link to justify text please choose option 1. Its work fine. And if you have any problem. Ask from author. I think he always happy to help you nice guy. As he helps me so much. And option 1 working with minor changes.
I am developing an Android Application. In this application, Logo bar is shown on all pages(Activities) or we can say it has header on all pages.
This Logo Bar have few icons like Home, Login, Notification, etc. and on Clicking on these icons corresponding navigation will perform.
for example if user is any where in application and click on home icon, he will navigate to the home page of application.
I am able to inflate logobar.XML into my All Activity by coding. but problem is i have to call onClickListener on all pages for all icons in Logo Bar.
This is not a good programming way.
How can i implement Logo Bar Activity in all other activity without repeating of code?
Is android have any Master Page concept as in .Net or tiles concept as in Struts?
Please guide me.
Edit: ok i got it. may be this answer will help you.
Try using Tab widget with tabactivity check this link for using fragment and tab http://developer.android.com/reference/android/app/TabActivity.html for android. i think for lower versions also we can use this. this si what the link says - "you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT."
you have to create your masterLayout in xml and that you have to include it in your other
layouts in which you have to have it.
The solution was pretty easy.
You need to extends "Activity" Class,in onCreate function SetContentView to your base xml layout and also need to override setContentView in base Activity Class
For Example:
1.Create "base_layout.xml" with the below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:padding="15dp" >
<LinearLayout android:orientation="horizontal" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="50dp" android:paddingLeft="10dp">
<ImageView android:layout_width="wrap_content" android:id="#+id/ImageView01"
android:adjustViewBounds="true" android:layout_height="wrap_content"
android:scaleType="fitCenter" android:maxHeight="50dp" />
</LinearLayout>
<LinearLayout android:id="#+id/linBase"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
2.Create "BaseActivity.java"
public class BaseActivity extends Activity {
ImageView image;
LinearLayout linBase;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.base_layout);
image = (ImageView)findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.header);
linBase = (LinearLayout)findViewById(R.id.linBase);
}
#Override
public void setContentView(int id) {
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(id, linBase);
}
}
and
public class SomeActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.some_layout);
//rest of code
}
}
The only thing I noticed so far was that when requesting a progress bar (requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) this needs to be done before calling super.onCreate. I think this is because nothing can be drawn yet before calling this function.
This worked great for me and hopefully you will find this useful in your own coding.
There is something like that, but only available on api 11+ (3.2 and Android 4.0.x Ice Cream Sandwich). Its called actionbar ( http://developer.android.com/reference/android/app/ActionBar.html).
I have done this using XML file.
I am just creating runtime view from XML file , and add it to the Activity layout.
I have created method for that
public static void setLoginview(Context ctx, RelativeLayout layout) {
LayoutInflater linflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = linflater.inflate(R.layout.loginheader, null);
layout.addView(myView);
try {
layout.getChildAt(0).setPadding(0, 50, 0, 0);
} catch (Exception e) {
}
}
ctx is the application contetx and layout is the layout in which i want to add that view.