Categories
discuss

Android layout, setting buttons to have the same size

I’m am completely new to programming android apps in eclipse.

With that said, I based myself off code on the internet and and came up with this xml file for my layout. I can not get the four buttons to have the same size, and when I play around with the other parts, the progress bar and texts under it, they go bananas, displaying it off screen.

Could someone review the code and tell me what is gong on? I simply don’t understand. Here is a picture.

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="10dp" >

        <TextView
            android:id="@+id/txt_currentDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_span="6"
            android:gravity="center"
            android:text="Current Date"
            android:textSize="18dp"
            android:textStyle="bold"
            android:typeface="serif" >
        </TextView>
    </TableRow>

    <TableRow
        android:id="@+id/progressBarRow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="5dp" >

        <ProgressBar
            android:id="@+id/DailyCalorieProgress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_span="3"
            android:progress="80" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="5dp" >

        <TextView
            android:id="@+id/textView1"
            android:gravity="center"
            android:text="Calorie Limit : "
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:id="@+id/textView2"
            android:gravity="center"
            android:text="2000  " >
        </TextView>

        <TextView
            android:id="@+id/textView3"
            android:gravity="center"
            android:text="Calories Left : "
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:id="@+id/textView4"
            android:gravity="center"
            android:text="552" >
        </TextView>
    </TableRow>

    <TextView
        android:id="@+id/textView5"
        android:gravity="center_horizontal"
        android:text="____________________" >
    </TextView>

    <TableLayout
        android:id="@+id/ButtonLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp"
        android:stretchColumns="0,1" >

        <TableRow
            android:id="@+id/buttonRow1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:paddingTop="10dp" >

        <Button
            android:id="@+id/btn_addFood"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="Add Food"/>

        <Button
            android:id="@+id/btn_addExercise"
            android:layout_width="130dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="Add Exercise"/>

        </TableRow>

        <TableRow
            android:id="@+id/buttonRow2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_recWeight"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"
            android:text="Record Weight" />

        <Button
            android:id="@+id/btn_sgstMeal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"
            android:text="Suggest Meal/Exercise" />

    </TableRow>
    </TableLayout>
</TableLayout>

Edits:

It now almost works.

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="10dp" >

        <TextView
            android:id="@+id/txt_currentDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_span="6"
            android:gravity="center"
            android:text="@string/CurrentDate"
            android:textSize="18dp"
            android:textStyle="bold"
            android:typeface="serif" >
        </TextView>
    </TableRow>

    <TableRow
        android:id="@+id/progressBarRow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="5dp" >

        <ProgressBar
            android:id="@+id/DailyCalorieProgress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_span="3"
            android:progress="80" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="5dp" >

        <TextView
            android:id="@+id/textView1"
            android:gravity="center"
            android:text="@string/CalorieLimit"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:id="@+id/textView2"
            android:gravity="center"
            android:text="@string/CalorieLimitData" >
        </TextView>

        <TextView
            android:id="@+id/textView3"
            android:gravity="center"
            android:text="@string/CaloriesLeft"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:id="@+id/textView4"
            android:gravity="center"
            android:text="@string/CaloriesLeftData" >
        </TextView>
    </TableRow>

    <TextView
        android:id="@+id/textView5"
        android:gravity="center_horizontal"
        android:text="@string/Line" >
    </TextView>



        <TableRow
            android:id="@+id/buttonRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:paddingTop="10dp" >

        <Button
            android:id="@+id/btn_addFood"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/AddFood"/>

        <Button
            android:id="@+id/btn_addExercise"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/AddExercise"/>

        </TableRow>

        <TableRow
            android:id="@+id/buttonRow2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:paddingTop="10dp" >

        <Button
            android:id="@+id/btn_recWeight"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/RecordWeight" />

        <Button
            android:id="@+id/btn_sgstMeal"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/SuggestedMeal_Exercise" />

    </TableRow>
</TableLayout>

Answer

Your layout isn’t really “efficient”. But anyway..to solve your problem you have to set your TableRow (the ones that contain your buttons) to

android:layout_width="fill_parent"
android:layout_height="wrap_content"

and all of your buttons to

android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"

0dip does not make anything. But because of the weight param android does the work for measuring the actual size anyway so you do not need to provide a “relevant” value

Categories
discuss

node.js returns GMT time and not local time for “new Date()”. Is that a bug?

If not a bug, how to tell node my timezone? If bug, is this reported already?

Answer

This is not a bug, just a choice of how Node decides to represent a Date object in its REPL. Also, as of node v0.7.x, this output has been changed to display local time, matching the browser behavior:

☮ ~ (master) ⚡ node
> process.version
'v0.7.7'
> new Date
Sat Mar 31 2012 15:12:13 GMT-0700 (PDT)
Categories
discuss

Smooth image fade out, change src, and fade in with jquery

I am trying to do the following:

On link click:

1.) fade out an img

2.) change the src of the now hidden image

3.) when the img with the new src finishes loading, fade in

Minimally, I’d like to see a smooth fade out of one image and a fade in of another (within the same img tag by changing the src)

Eventually I’d like to:

1.) fade out an img

2.) show a animated gif “loading image”

3.) change the src of the now hidden image

4.) hide the animated gif “loading image”

5.) when the img with the new src finishes loading, fade in

Thanks.

This is what I tried so far. It seems to do a couple flashes but only after the src changes (prior to the fade out). Strange behavior.

$("#Image").fadeOut();
$("#Image").attr("src", NEW_IMAGE_SRC);
$("#Image").fadeIn();

#Image is an IMG tag

Answer

Try this:

$('.click').click(function() {
   $('img.class').fadeOut(300, function(){
      $(this).attr('src','new_src.png').bind('onreadystatechange load', function(){
         if (this.complete) $(this).fadeIn(300);
      });
   });
});
Categories
discuss

How can i extract bz2 file in Java on Android?

How can i extract bz2 file in Java on Android? Are any included libraries in android?

Answer

My best bet would be to try Apache Commons Compress. It has a built-in bzip2 (de)compressor: example. I’m not particularly sure though it will run on Android out of the box, but worth a try I’d say.

Alternatively, you might want to take a look at the bzip2/libzip2 library compiled for Android.

Categories
discuss

Is using ActionBarSherlock still necessary?

Up until earlier today, I was under the impression that if I wanted to use ActionBar on devices lower than SDK version 11, I would need to use ABS. But, after looking at some questions on SO here, I came upon this: http://developer.android.com/resources/samples/ActionBarCompat/index.html

This system looks like it provides a fully functioning actionbar system on preHoneycomb devices. Specifically, though I don’t see anything in those classes concerning actionbar tabs. Has anyone managed to use this actionbarhelper class with actionbartabs?

Does anyone have any experience using both of these systems? I’m having a heck of a time trying to import my android project to work with ABS, whether it was getting my R file to link, bringing the manifest into the folder, getting the correct package names so my activities would launch, and beyond all that, the highly cluttered src folder. So if it’s possible to use this Google-provided code instead, I think it might be desirable – if it is possble to use tabs?

Answer

This system looks like it provides a fully functioning actionbar system on preHoneycomb devices.

ActionBarCompat is not “fully functioning”, as compared to the native action bar or ActionBarSherlock.

Has anyone managed to use this actionbarhelper class with actionbartabs?

It does not support tabs.

I’m having a heck of a time trying to import my android project to work with ABS, whether it was getting my R file to link, bringing the manifest into the folder, getting the correct package names so my activities would launch, and beyond all that, the highly cluttered src folder.

Step #1: Download the ABS ZIP file.

Step #2: Import the project (in library/) into Eclipse, marking it to compile with Android 4.0 or higher.

Step #3: Add it as a library project to your existing project.

Step #4: Inherit from SherlockActivity or related classes (e.g., SherlockListActivity), and update other references (e.g., MenuInflater) to Sherlock equivalents as needed.

Step #5: Add Theme.Sherlock to your <application> or <activity> elements.

And that’s pretty much it, beyond what you would ordinarily do to use the native action bar.

So if it’s possible to use this Google-provided code instead, I think it might be desirable

Code in the “samples” area of the Android Developers site is just that: sample code. The code is unsupported, un-maintained (some don’t even work anymore), etc. If you would prefer to use such code over a component that has many more engineers using it, has its own support group, etc., you are welcome to do so.

This is my first application on Android and it’s been a beast just getting to the point where I can say I have a fully functioning ViewPager, TabAdapter, system of fragment tabs, and some basic login/register features from an SQL server.

Then perhaps you should start with a simpler app. What you are describing is not what I would recommend somebody start with, unless they are getting specific guidance (e.g., a set of tutorials).

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..