[Q] ListView appearance changes - Java for Android App Development

I have created an android program which contains listview. Emulator and my phone (Samsung Galaxy S) shows like;
-see First Attachment (1.png)
But when I open my program in Samsung Note 3, it shows like;
-see Second Attachment (2.png)
It likes 2 empty rows(empty but their colors dark blue) and 1 real list view item. 2 empty rows, 1 real item, 2 empty rows, 1 real item ....
I tried each of item in listview. I removed each one and it does not solve my problem. And some bigger screen phones have same issue. How can i solve it?
my xml:
Code:
<RelativeLayout
android:id="@+id/tabTT"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/tabTT_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team Tactics"
android:id="@+id/tabTT_main_text"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#800000"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_main_second"
android:textSize="12sp"
android:textColor="#000000"
android:visibility="invisible"
android:layout_below="@id/tabTT_main_text"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabTT_listView"
android:clickable="true"
android:layout_below="@id/tabTT_main_second"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ImageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_name"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_subName"
android:textSize="12sp"
android:layout_below="@id/tabTT_textView_name"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ProgressBar"
android:layout_below="@id/tabTT_textView_subName"
android:layout_toRightOf="@id/tabTT_ImageView"
android:progressDrawable="@drawable/progress_bar"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_percentage"
android:layout_centerHorizontal="true"
android:layout_below="@id/tabTT_textView_subName"
android:textColor="#800000"/>
</RelativeLayout>
my adapter:
Code:
public static class TTAdapter extends ArrayAdapter<Achievement> {
public TTAdapter(Context context, ArrayList<Achievement> users) {
super(context, 0, users);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Achievement user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_ach, parent, false);
}
convertView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Achievement clicked = getItem(position);
if(clicked.progressFloatSecond!=-1){
Toast.makeText(getContext(), "Left: " + NumberFormat.getNumberInstance(Locale.US).format(clicked.progressFloatSecond - clicked.progressFloatFirst), Toast.LENGTH_SHORT).show();
}
else Toast.makeText(getContext(), "One-Time Mission!", Toast.LENGTH_SHORT).show();
}
});
TextView name = (TextView) convertView.findViewById(R.id.tabTT_textView_name);
TextView subName = (TextView) convertView.findViewById(R.id.tabTT_textView_subName);
ImageView imVi = (ImageView)convertView.findViewById(R.id.tabTT_ImageView);
ProgressBar progBar = (ProgressBar) convertView.findViewById(R.id.tabTT_ProgressBar);
TextView percentageFloat = (TextView) convertView.findViewById(R.id.tabTT_textView_percentage);
DecimalFormat df = new DecimalFormat("##.##");
name.setText(user.name);
subName.setText(user.subName);
imVi.setImageResource(user.picInt);
progBar.setVisibility(View.INVISIBLE);
percentageFloat.setVisibility(View.INVISIBLE);
if(user.progressFloatSecond!=-1){
progBar.setVisibility(View.VISIBLE);
progBar.setMax(user.progressFloatSecond);
progBar.setProgress(user.progressFloatFirst);
percentageFloat.setText(df.format(user.progressFloat) + " %");
percentageFloat.setVisibility(View.VISIBLE);
}
return convertView;
}
}

Maybe you can try the layout development tool to show the view border.
Open it in Settings->Developer options->Show layout bounds.
anilff said:
I have created an android program which contains listview. Emulator and my phone (Samsung Galaxy S) shows like;
-see First Attachment (1.png)
But when I open my program in Samsung Note 3, it shows like;
-see Second Attachment (2.png)
It likes 2 empty rows(empty but their colors dark blue) and 1 real list view item. 2 empty rows, 1 real item, 2 empty rows, 1 real item ....
I tried each of item in listview. I removed each one and it does not solve my problem. And some bigger screen phones have same issue. How can i solve it?
my xml:
Code:
<RelativeLayout
android:id="@+id/tabTT"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/tabTT_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Team Tactics"
android:id="@+id/tabTT_main_text"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#800000"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_main_second"
android:textSize="12sp"
android:textColor="#000000"
android:visibility="invisible"
android:layout_below="@id/tabTT_main_text"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabTT_listView"
android:clickable="true"
android:layout_below="@id/tabTT_main_second"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ImageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_name"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_subName"
android:textSize="12sp"
android:layout_below="@id/tabTT_textView_name"
android:textColor="#000000"
android:layout_marginLeft="68dp"/>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tabTT_ProgressBar"
android:layout_below="@id/tabTT_textView_subName"
android:layout_toRightOf="@id/tabTT_ImageView"
android:progressDrawable="@drawable/progress_bar"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabTT_textView_percentage"
android:layout_centerHorizontal="true"
android:layout_below="@id/tabTT_textView_subName"
android:textColor="#800000"/>
</RelativeLayout>
my adapter:
Code:
public static class TTAdapter extends ArrayAdapter<Achievement> {
public TTAdapter(Context context, ArrayList<Achievement> users) {
super(context, 0, users);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Achievement user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_ach, parent, false);
}
convertView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Achievement clicked = getItem(position);
if(clicked.progressFloatSecond!=-1){
Toast.makeText(getContext(), "Left: " + NumberFormat.getNumberInstance(Locale.US).format(clicked.progressFloatSecond - clicked.progressFloatFirst), Toast.LENGTH_SHORT).show();
}
else Toast.makeText(getContext(), "One-Time Mission!", Toast.LENGTH_SHORT).show();
}
});
TextView name = (TextView) convertView.findViewById(R.id.tabTT_textView_name);
TextView subName = (TextView) convertView.findViewById(R.id.tabTT_textView_subName);
ImageView imVi = (ImageView)convertView.findViewById(R.id.tabTT_ImageView);
ProgressBar progBar = (ProgressBar) convertView.findViewById(R.id.tabTT_ProgressBar);
TextView percentageFloat = (TextView) convertView.findViewById(R.id.tabTT_textView_percentage);
DecimalFormat df = new DecimalFormat("##.##");
name.setText(user.name);
subName.setText(user.subName);
imVi.setImageResource(user.picInt);
progBar.setVisibility(View.INVISIBLE);
percentageFloat.setVisibility(View.INVISIBLE);
if(user.progressFloatSecond!=-1){
progBar.setVisibility(View.VISIBLE);
progBar.setMax(user.progressFloatSecond);
progBar.setProgress(user.progressFloatFirst);
percentageFloat.setText(df.format(user.progressFloat) + " %");
percentageFloat.setVisibility(View.VISIBLE);
}
return convertView;
}
}
Click to expand...
Click to collapse

Related

How to set the background of an activity

Ok so im just practising my android skills. What I did was basically make an app that lets the user choose what image to set as the wallpaper or the background of the app.
Ive set the wallpaper up but couldnt find a way to setting the background up for the app/activity.
XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/IVDisplay"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/bentley" />
<HorizontalScrollView
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="100dp" >
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img1"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
android:src="@drawable/bentley" />
<ImageView
android:id="@+id/img2"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
android:src="@drawable/bugatti" />
<ImageView
android:id="@+id/img3"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
android:src="@drawable/dodge" />
<ImageView
android:id="@+id/img4"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/img5"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
android:src="@drawable/rollsroyce" />
</LinearLayout>
</HorizontalScrollView>
<Button
android:id="@+id/wallpaperbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set as wallpaper" />
<Button
android:id="@+id/bkgbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set as Background" />
</LinearLayout>
Java:
Code:
package com.examples.hello;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class PAGEONE extends Activity implements OnClickListener {
ImageView display;
int tophone;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bkgd);
display = (ImageView) findViewById(R.id.IVDisplay);
tophone = R.drawable.bentley;
Button wallpap = (Button) findViewById(R.id.wallpaperbutton);
Button bkg = (Button) findViewById(R.id.bkgbutton);
ImageView img1 = (ImageView) findViewById(R.id.img1);
ImageView img2 = (ImageView) findViewById(R.id.img2);
ImageView img3 = (ImageView) findViewById(R.id.img3);
ImageView img4 = (ImageView) findViewById(R.id.img4);
ImageView img5 = (ImageView) findViewById(R.id.img5);
img1.setOnClickListener(this);
img2.setOnClickListener(this);
img3.setOnClickListener(this);
img4.setOnClickListener(this);
img5.setOnClickListener(this);
wallpap.setOnClickListener(this);
}
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.img1:
display.setImageResource(R.drawable.bentley);
tophone = R.drawable.bentley;
break;
case R.id.img2:
display.setImageResource(R.drawable.bugatti);
tophone = R.drawable.bugatti;
break;
case R.id.img3:
display.setImageResource(R.drawable.dodge);
tophone = R.drawable.dodge;
break;
case R.id.img4:
display.setImageResource(R.drawable.ic_launcher);
tophone = R.drawable.ic_launcher;
break;
case R.id.img5:
display.setImageResource(R.drawable.rollsroyce);
tophone = R.drawable.rollsroyce;
break;
case R.id.wallpaperbutton:
InputStream yea = getResources().openRawResource(tophone);
Bitmap hmm = BitmapFactory.decodeStream(yea);
WallpaperManager mywallpaper = WallpaperManager.getInstance(getApplicationContext ());
try{
mywallpaper.setResource(tophone);
}catch(IOException e){
e.printStackTrace();
}
}
}
}
I dont know what methods to use. I was thinking of setting up individual pictures as the layouts (so I'd have 5 extra layouts since I have 5 pictures), but that wouldn't make any sense.
You need to give your linearlayout an id and then find the view by normal ways and use:
yourLayout.setBackgroundDrawable(Drawable d);
Code:
LinearLayout linLay = (LinearLayout) findViewById(R.id.theLinearLayoutId);
//set background to a color
linLay.setBackgroundColor("#404040");
//set background to a drawable
linLay.setBackgroundDrawable(drawableItem);
//set background to a resource
linLay.setBackgroundResource(R.id.backgroundResource);
Or just
Code:
getWindow().getDecorView().setBackgroundDrawable(*yourDrawable*);
After setContentView
Thanks for your help guys. I followed Chris95x8's advice since its only one line of code and really, who can deny one line of code??
Anyways, took a few tries to make it work but finally did it. I put that statement after the set content view but got errors and plus that statement is deprecated so I used this methd:
getWindow().getDecorView().setBackgroundResource();
I just pasted it into the switch statement I created earlier:
case R.id.bkgbutton:
getWindow().getDecorView().setBackgroundResource(tophone);
break;
Whilst I was at it, created a few toasts letting the user know the background/wallpaper has been set.
One thing I dont understand, what does it mean by context? For example, when using the toast method:
Toast df = Toast.makeText(context, text, duration)
What does the context mean in the bracket/parenthesis ?
TwilightLoz said:
Thanks for your help guys. I followed Chris95x8's advice since its only one line of code and really, who can deny one line of code??
Anyways, took a few tries to make it work but finally did it. I put that statement after the set content view but got errors and plus that statement is deprecated so I used this methd:
getWindow().getDecorView().setBackgroundResource();
I just pasted it into the switch statement I created earlier:
case R.id.bkgbutton:
getWindow().getDecorView().setBackgroundResource(tophone);
break;
Whilst I was at it, created a few toasts letting the user know the background/wallpaper has been set.
One thing I dont understand, what does it mean by context? For example, when using the toast method:
Toast df = Toast.makeText(context, text, duration)
What does the context mean in the bracket/parenthesis ?
Click to expand...
Click to collapse
Hi,
Please check this out to know what the Context class does - http://stackoverflow.com/questions/3572463/what-is-context-in-android
Good luck

TextView shows wrong text

Hi,
i'm reading a book about android app development (Learn Android App Development by Wallace Jackson).
But i'm having troubles with my TextViews..
This is what i get when i open the app on the android emulator:
It is supposed to show data like the planet name, mass, gravity,... I tried to locate the mistake in the code, but i never found it..
I want to copy paste the code, but maybe it's easier if i post the entire project
https://www.dropbox.com/sh/235c7k0psaoejxk/I903eizE7A
Could anyone help me find the bug? :/
I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...
Thanks
coolbud012 said:
I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...
Thanks
Click to expand...
Click to collapse
Oh yeah sorry, I didn't think of that.
This is the XML:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/dataView1"
android:layout_toRightOf="@+id/textView1"
android:layout_marginLeft="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label"
android:layout_below="@+id/textView1"/>
<TextView
android:id="@+id/dataView2"
android:layout_toRightOf="@+id/textView2"
android:layout_alignStart="@+id/dataView1"
android:layout_below="@+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label"
android:layout_below="@+id/textView2"/>
<TextView
android:id="@+id/dataView3"
android:layout_toRightOf="@+id/textView3"
android:layout_alignStart="@+id/dataView2"
android:layout_below="@+id/dataView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label"
android:layout_below="@+id/textView3"/>
<TextView android:id="@+id/dataView4"
android:layout_toRightOf="@+id/textView4"
android:layout_alignStart="@+id/dataView3"
android:layout_below="@+id/dataView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label"
android:layout_below="@+id/textView4"/>
<TextView
android:id="@+id/dataView5"
android:layout_toRightOf="@+id/textView5"
android:layout_alignStart="@+id/dataView4"
android:layout_below="@+id/dataView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label"
android:layout_below="@+id/textView5"/>
<TextView
android:id="@+id/dataView6"
android:layout_toRightOf="@+id/textView6"
android:layout_alignStart="@+id/dataView5"
android:layout_below="@+id/dataView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label"
android:layout_below="@+id/textView6"/>
<TextView
android:id="@+id/dataView7"
android:layout_toRightOf="@+id/textView7"
android:layout_alignStart="@+id/dataView6"
android:layout_below="@+id/dataView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"
android:layout_below="@+id/textView7"/>
<TextView
android:id="@+id/dataView8"
android:layout_toRightOf="@+id/textView8"
android:layout_alignStart="@+id/dataView7"
android:layout_below="@+id/dataView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"/>
</RelativeLayout>
And this is the java:
Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
WorldGen earth = new WorldGen("Earth", 5973, 9.78);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setStartUpWorldValues();
}
protected void setStartUpWorldValues() {
earth.setPlanetColonies(1);
earth.setPlanetMilitary(1);
earth.setColonyImmigration(1000);
earth.setBaseProtection(100);
earth.turnForceFieldOn();
}
@SuppressWarnings("unused")
private void setStartUpScreenText() {
TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
planetNameValue.setText(earth.planetName);
TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
planetMassValue.setText(String.valueOf(earth.planetMass));
TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
planetGravityValue.setText(String.valueOf(earth.planetGravity));
TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
planetColoniesValue.setText(String.valueOf(earth.planetColonies));
TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
planetBasesValue.setText(String.valueOf(earth.planetBases));
TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Xintax said:
Oh yeah sorry, I didn't think of that.
This is the XML:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/dataView1"
android:layout_toRightOf="@+id/textView1"
android:layout_marginLeft="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_name_label" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label"
android:layout_below="@+id/textView1"/>
<TextView
android:id="@+id/dataView2"
android:layout_toRightOf="@+id/textView2"
android:layout_alignStart="@+id/dataView1"
android:layout_below="@+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_mass_label" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label"
android:layout_below="@+id/textView2"/>
<TextView
android:id="@+id/dataView3"
android:layout_toRightOf="@+id/textView3"
android:layout_alignStart="@+id/dataView2"
android:layout_below="@+id/dataView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_gravity_label" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label"
android:layout_below="@+id/textView3"/>
<TextView android:id="@+id/dataView4"
android:layout_toRightOf="@+id/textView4"
android:layout_alignStart="@+id/dataView3"
android:layout_below="@+id/dataView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_colonies_label" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label"
android:layout_below="@+id/textView4"/>
<TextView
android:id="@+id/dataView5"
android:layout_toRightOf="@+id/textView5"
android:layout_alignStart="@+id/dataView4"
android:layout_below="@+id/dataView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_population_label" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label"
android:layout_below="@+id/textView5"/>
<TextView
android:id="@+id/dataView6"
android:layout_toRightOf="@+id/textView6"
android:layout_alignStart="@+id/dataView5"
android:layout_below="@+id/dataView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_military_label" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label"
android:layout_below="@+id/textView6"/>
<TextView
android:id="@+id/dataView7"
android:layout_toRightOf="@+id/textView7"
android:layout_alignStart="@+id/dataView6"
android:layout_below="@+id/dataView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_bases_label" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"
android:layout_below="@+id/textView7"/>
<TextView
android:id="@+id/dataView8"
android:layout_toRightOf="@+id/textView8"
android:layout_alignStart="@+id/dataView7"
android:layout_below="@+id/dataView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/planet_forcefield_label"/>
</RelativeLayout>
And this is the java:
Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
WorldGen earth = new WorldGen("Earth", 5973, 9.78);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setStartUpWorldValues();
}
protected void setStartUpWorldValues() {
earth.setPlanetColonies(1);
earth.setPlanetMilitary(1);
earth.setColonyImmigration(1000);
earth.setBaseProtection(100);
earth.turnForceFieldOn();
}
@SuppressWarnings("unused")
private void setStartUpScreenText() {
TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
planetNameValue.setText(earth.planetName);
TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
planetMassValue.setText(String.valueOf(earth.planetMass));
TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
planetGravityValue.setText(String.valueOf(earth.planetGravity));
TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
planetColoniesValue.setText(String.valueOf(earth.planetColonies));
TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
planetBasesValue.setText(String.valueOf(earth.planetBases));
TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
Have gone through this but didnt get what exactly you are trying to achieve...Also you have posted the main Activity in which you have created a member of "WorldGen" , whats in this class?
Actually to be frank I didnt get what exactly you are trying to do here...
I would be good if you make an image in "Paint" , rough image, and show what you are exactly trying to achieve?
Thanks
---------- Post added at 09:07 PM ---------- Previous post was at 09:06 PM ----------
If possible upload the project on Github.com
Well i'm trying to get the text on the left to change into the planet name (earth) planet gravity (9.8),...
I think i can't make it more clear with a paint image with my painting skills
I'm setting up github as we speak, i'll upload it in a sec.
EDIT: Here it is: https://github.com/Xintax/HlloWrld
Thanks!
Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?
Regards
Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.
EmptinessFiller said:
Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?
Regards
Click to expand...
Click to collapse
SimplicityApks said:
Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.
Click to expand...
Click to collapse
Well i tried to hard-code the values, and that works.. But my idea is that users can change the planet, and can make their own, so i can't hard-code the values because then they can't change :/
I'll try if the listview works, it does take a long time

[Q] How to achieve this Custom layout

I have tried the frame layout and sliderView all seemed abortive..
my aim is to slide a layout from below when a button is clicked and the layout shouldn't cover the whole screen just the height should wrap_content some thing like the image below
i am a newbie in android development so don't blame my ignorance thnak you as you help
no reply? please guys help a noob...
mashnino said:
no reply? please guys help a noob...
Click to expand...
Click to collapse
question is a little ambiguous and it's just a viewGroup afterall, there are 100's of implementation options. Personally I would use a fragmentDialog, but I could just as easy use any normal viewGroup.
deanwray said:
question is a little ambiguous and it's just a viewGroup afterall, there are 100's of implementation options. Personally I would use a fragmentDialog, but I could just as easy use any normal viewGroup.
Click to expand...
Click to collapse
okay dat was a little out of my league..can u like give me an example...
because this is what i have already... a layout within a layout and then some button in which onClick() it slides the layout from below.
the main problem is the layout doesnt stick to the bottom of the screen.. instead it slides to the top of the screen.
activity_main.xml
PHP:
<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:background="@color/blue"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eeeeee"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/action_bar"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@color/blue" >
<ImageButton
android:id="@+id/qpaper_menu"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/menu_button_blue" />
<TextView
android:id="@+id/app_header_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/qpaper_menu"
android:text="UMAR MASH"
android:textColor="#fff"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="12dp"
android:background="@drawable/bg_card"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Umar mash was ere...."
android:layout_alignParentLeft="true"/>
<Button
android:id="@+id/slider"
android:layout_below="@id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sleider"
android:onClick="slider"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/hidden_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
android:background="#000000" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />
</LinearLayout>
</RelativeLayout>
and then the main_activity.java class
PHP:
package com.example.kkn;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
ActionBar ab;
ImageButton side;
boolean isPanelDown;
View hiddenpanel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
side = (ImageButton) findViewById(R.id.qpaper_menu);
hiddenpanel = findViewById(R.id.hidden_panel);
ab = getActionBar();
ab.hide();
side.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.qpaper_menu:
Toast.makeText(getApplicationContext(), "This is the menu button", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
public void slider(final View view) {
if (!isPanelShown()) {
// Show the panel
Animation bottomUp = AnimationUtils.loadAnimation(this,R.anim.bottom_up);
hiddenpanel.startAnimation(bottomUp);
hiddenpanel.setVisibility(View.VISIBLE);
}
else {
// Hide the Panel
Animation bottomDown = AnimationUtils.loadAnimation(this,R.anim.bottom_down);
hiddenpanel.startAnimation(bottomDown);
hiddenpanel.setVisibility(View.GONE);
}
}
private boolean isPanelShown() {
return hiddenpanel.getVisibility() == View.VISIBLE;
}
}
so any help please
mashnino said:
okay dat was a little out of my league..can u like give me an example...
so any help please
Click to expand...
Click to collapse
There are many examples of view animation both on the developer website and on SO. Sounds like you just need to set animate Y position to move relative ((screen height - (screen height - height of sliding view)) ?
Or just end at absolute (screen height - height of sliding view)
deanwray said:
There are many examples of view animation both on the developer website and on SO. Sounds like you just need to set animate Y position to move relative ((screen height - (screen height - height of sliding view)) ?
Or just end at absolute (screen height - height of sliding view)
Click to expand...
Click to collapse
i would have known what to do if i actually understood where to put the code... please can you like fork the code so that i can have an idea of what you are saying and from there i can look up other resources... please
mashnino said:
i would have known what to do if i actually understood where to put the code... please can you like fork the code so that i can have an idea of what you are saying and from there i can look up other resources... please
Click to expand...
Click to collapse
sounds like your wanting someone to write it for you ?
If not then you should just look at doing what I said, getting the height and working out the end position for the anim and setting it programmatically. If you need hints ask away but not sure I have the time to write it for you atm...sorry

listView Resize animation

I have this custom listView:
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableRow">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/imdDesc" />
<TextView
android:id="@+id/titleList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="25sp"
android:autoText="false"
android:gravity="center_vertical|center|center_horizontal" />
</TableRow>
This adapter:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] title;
private final int[] colors;
private final Integer[] imageId;
public CustomList(Activity context,String[] title,int[] colors, Integer[] imageId) {
super(context, R.layout.list_single, title);
this.context = context;
this.title = title;
this.imageId = imageId;
this.colors=colors;
}
@override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titleList);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(title[position]);
txtTitle.setTextColor(Color.parseColor("#FFffffff"));
txtTitle.setBackgroundColor(colors[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
and this is how I bind them:
final CustomList adapter = new
CustomList(MainActivity.this, title, colors, imageId);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
My list has 12 items. I need to resize the list when user click one item. If the user choses an Item for the first time, the list has to change its width to 1/3 of its original size and to double the height of the selected item. If an item is already selected in the list and the user selects another the old item has to go back to the original height and the new selected one has to double its height without any width changes.
I want to animate all the resizing for nice looking.
This is the animation for changing width:
public class ShrinkList extends Animation
{
int fromWidth;
View view;
int def;
public ShrinkList(View view) {
this.view = view;
this.fromWidth = view.getWidth();
def=fromWidth/3;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
newWidth = (int) ((def - fromWidth) * interpolatedTime + fromWidth);
if (newWidth > def/3) {
view.getLayoutParams().width = newWidth;
view.requestLayout();
}
else{
view.getLayoutParams().width = def/3;
view.requestLayout();
}
}
}
and this one is for changing height:
public class Grow extends Animation
{
int fromHeight;
View view;
int defaultHeight;
public Grow(View view,int height) {
this.view = view;
this.fromHeight = view.getHeight();
defaultHeight=height;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
newHeight = (int) (fromHeight / (1 - interpolatedTime));
if (newHeight < defaultHeight * 2) {
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
else{
view.getLayoutParams().height = defaultHeight*2;
view.requestLayout();
}
}
}
and I play them like that:
if(h==0) { //first time the user selects an item =>change width and height
Animation a = new ShrinkList(list);
a.setInterpolator(new LinearInterpolator());
a.setDuration(1000);
list.setAnimation(a);
list.startAnimation(a);
}
Animation a1 = new Grow(view,height); //change only height
a1.setInterpolator(new LinearInterpolator());
a1.setDuration(300);
view.setAnimation(a1);
view.startAnimation(a1);
My problem is that when the list changes its width, the animation is not smooth at all and it only changes the width, not the height too.
How can I make the animation smoother and make the two animations play at once?
I have tried scaling the list, but that scales all the list. basically I need only to resize the textView within ListView nd changing layoutParams does that.
I have tried to insert the code from Grow.java into ShrinkList.Java in orefer to play both animations once and it only played the one from Grow.java.
Jaws1992 said:
I have this custom listView:
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableRow">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/imdDesc" />
<TextView
android:id="@+id/titleList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="25sp"
android:autoText="false"
android:gravity="center_vertical|center|center_horizontal" />
</TableRow>
This adapter:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] title;
private final int[] colors;
private final Integer[] imageId;
public CustomList(Activity context,String[] title,int[] colors, Integer[] imageId) {
super(context, R.layout.list_single, title);
this.context = context;
this.title = title;
this.imageId = imageId;
this.colors=colors;
}
@override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titleList);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(title[position]);
txtTitle.setTextColor(Color.parseColor("#FFffffff"));
txtTitle.setBackgroundColor(colors[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
and this is how I bind them:
final CustomList adapter = new
CustomList(MainActivity.this, title, colors, imageId);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
My list has 12 items. I need to resize the list when user click one item. If the user choses an Item for the first time, the list has to change its width to 1/3 of its original size and to double the height of the selected item. If an item is already selected in the list and the user selects another the old item has to go back to the original height and the new selected one has to double its height without any width changes.
I want to animate all the resizing for nice looking.
This is the animation for changing width:
public class ShrinkList extends Animation
{
int fromWidth;
View view;
int def;
public ShrinkList(View view) {
this.view = view;
this.fromWidth = view.getWidth();
def=fromWidth/3;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
newWidth = (int) ((def - fromWidth) * interpolatedTime + fromWidth);
if (newWidth > def/3) {
view.getLayoutParams().width = newWidth;
view.requestLayout();
}
else{
view.getLayoutParams().width = def/3;
view.requestLayout();
}
}
}
and this one is for changing height:
public class Grow extends Animation
{
int fromHeight;
View view;
int defaultHeight;
public Grow(View view,int height) {
this.view = view;
this.fromHeight = view.getHeight();
defaultHeight=height;
}
@override
public boolean willChangeBounds() {
return true;
}
@override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
newHeight = (int) (fromHeight / (1 - interpolatedTime));
if (newHeight < defaultHeight * 2) {
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
else{
view.getLayoutParams().height = defaultHeight*2;
view.requestLayout();
}
}
}
and I play them like that:
if(h==0) { //first time the user selects an item =>change width and height
Animation a = new ShrinkList(list);
a.setInterpolator(new LinearInterpolator());
a.setDuration(1000);
list.setAnimation(a);
list.startAnimation(a);
}
Animation a1 = new Grow(view,height); //change only height
a1.setInterpolator(new LinearInterpolator());
a1.setDuration(300);
view.setAnimation(a1);
view.startAnimation(a1);
My problem is that when the list changes its width, the animation is not smooth at all and it only changes the width, not the height too.
How can I make the animation smoother and make the two animations play at once?
I have tried scaling the list, but that scales all the list. basically I need only to resize the textView within ListView nd changing layoutParams does that.
I have tried to insert the code from Grow.java into ShrinkList.Java in orefer to play both animations once and it only played the one from Grow.java.
Click to expand...
Click to collapse
Do it like this
Code:
<RelativeLayout
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]/>
</RelativeLayout>
Then you only need to change the width and height. And you don't have to worry about the animation
Rick Clephas said:
Do it like this
Code:
<RelativeLayout
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
[B]android:animateLayoutChanges="true"[/B]/>
</RelativeLayout>
Then you only need to change the width and height. And you don't have to worry about the animation
Click to expand...
Click to collapse
I have tried what you suggested and the relative layout works great, but the list doesn't animate when it changes its witdh
Jaws1992 said:
I have tried what you suggested and the relative layout works great, but the list doesn't animate when it changes its witdh
Click to expand...
Click to collapse
You should add the animate layout changes to the first parent with match_parent as width
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
You should add the animate layout changes to the first parent with match_parent as width
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
I created a relative layout as in your example and added animate layout changes to both the listview and that layout and changed the witth of the layout and it doesn't animate the list getting smaller. Only the next relative layout getting bigger after the list is small
Jaws1992 said:
I created a relative layout as in your example and added animate layout changes to both the listview and that layout and changed the witth of the layout and it doesn't animate the list getting smaller. Only the next relative layout getting bigger after the list is small
Click to expand...
Click to collapse
Okey. AnimateLayoutChanges applies to the chields. So if you want to animate the relative layout the listview is in. You need to add animateLayoutChanges to his parent
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Okey. AnimateLayoutChanges applies to the chields. So if you want to animate the relative layout the listview is in. You need to add animateLayoutChanges to his parent
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
I added animate layout changes to all the listView ancestors and it still doesn't animate the listView.
This is the java code for changing width. Maybe I doing something wrong here:
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) linLay.getLayoutParams();
if(sdkVersion>=Build.VERSION_CODES.HONEYCOMB) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
lp.width =size.x/3;
}
else{
Display display = getWindowManager().getDefaultDisplay();
lp.width = display.getWidth()/3;
}
linLay.setLayoutParams(lp); //linLay is the listView parrent and is a relativeLayout
Jaws1992 said:
I added animate layout changes to all the listView ancestors and it still doesn't animate the listView.
This is the java code for changing width. Maybe I doing something wrong here:
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) linLay.getLayoutParams();
if(sdkVersion>=Build.VERSION_CODES.HONEYCOMB) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
lp.width =size.x/3;
}
else{
Display display = getWindowManager().getDefaultDisplay();
lp.width = display.getWidth()/3;
}
linLay.setLayoutParams(lp); //linLay is the listView parrent and is a relativeLayout
Click to expand...
Click to collapse
You have to set the animateLayoutChanges to the paretn of linLay
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
You have to set the animateLayoutChanges to the paretn of linLay
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Yes, I have already done that.As I said, I added animate layout changes to all of the listview ancestosr meaning linLay, parent of linLay, parent of parent of linLay and so on until the root of layouts, but the listView still doesn't animate
Okey could you post your xml
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Okey could you post your xml
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
<LinearLayout
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:id="@+id/titleLayout"
android:visibility="visible"
android:animateLayoutChanges="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imagew"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/share"
android:layout_alignEnd="@+id/share"
android:layout_toRightOf="@+id/imagew"
android:layout_toEndOf="@+id/imagew"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/title"
android:textSize="40sp"
android:gravity="center|right"
android:layout_gravity="left"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/date"
android:textSize="30sp"
android:gravity="clip_horizontal|center|center_horizontal"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:textColor="#ffffffff"
android:textStyle="italic" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/share"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="@drawable/share"
android:adjustViewBounds="false"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="false"
android:layout_centerVertical="true"
android:contentDescription="@string/share" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linLay"
android:animateLayoutChanges="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:headerDividersEnabled="false"
android:dividerHeight="0dp"
android:animateLayoutChanges="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_toRightOf="@id/linLay"
android:id="@+id/contentLayout"
android:animateLayoutChanges="true">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="30sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"
android:textColor="#ffffffff"
android:typeface="normal"
android:gravity="left|fill" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="#ff647ab1"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:background="@drawable/fb" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/FB"
android:id="@+id/fb"
android:textColor="#ffffffff"
android:textStyle="bold"
android:textSize="50sp" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Jaws1992 said:
<LinearLayout
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:id="@+id/titleLayout"
android:visibility="visible"
android:animateLayoutChanges="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imagew"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/share"
android:layout_alignEnd="@+id/share"
android:layout_toRightOf="@+id/imagew"
android:layout_toEndOf="@+id/imagew"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/title"
android:textSize="40sp"
android:gravity="center|right"
android:layout_gravity="left"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/date"
android:textSize="30sp"
android:gravity="clip_horizontal|center|center_horizontal"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:textColor="#ffffffff"
android:textStyle="italic" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/share"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="@drawable/share"
android:adjustViewBounds="false"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="false"
android:layout_centerVertical="true"
android:contentDescription="@string/share" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linLay"
android:animateLayoutChanges="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
android:headerDividersEnabled="false"
android:dividerHeight="0dp"
android:animateLayoutChanges="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_toRightOf="@id/linLay"
android:id="@+id/contentLayout"
android:animateLayoutChanges="true">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="30sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"
android:textColor="#ffffffff"
android:typeface="normal"
android:gravity="left|fill" />
<LinearLayout
androidrientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="#ff647ab1"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:background="@drawable/fb" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/FB"
android:id="@+id/fb"
android:textColor="#ffffffff"
android:textStyle="bold"
android:textSize="50sp" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Click to expand...
Click to collapse
Does the width change?
Sent from my SM-N9005 using XDA Premium 4 mobile app
Rick Clephas said:
Does the width change?
Sent from my SM-N9005 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Yes. The width of changes, but it doesn't animate
Jaws1992 said:
Yes. The width of changes, but it doesn't animate
Click to expand...
Click to collapse
Okey I don't get it. It should work...
Sent from my SM-N9005 using XDA Premium 4 mobile app

Text in a spinner changes height and width selecting another item

I wrote this code for an Android spinner:
Code:
<Spinner
android:id="@+id/lstCommunity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/community_string"
android:layout_alignLeft="@+id/txtName"
android:layout_below="@+id/txtName"
android:minHeight="0dp"
android:textSize="10sp"
android:background="@drawable/box" />
But the text in the spinner changes its height and width after selecting another item in the list.
So, initially it is a bit smaller than the height and width of the spinner, after selecting another item, it becomes really bigger than the spinner's size.
How should i change my code?
1) Creare spinnertext.xml in res/layout
For example:
Code:
xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=
android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#FFFFFFFF"
android:gravity="center"/>
2)Declare the spinner in the file main.xml (in res\layout), to manage its size :
Code:
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="32dip"
android:drawSelectorOnTop="true"
android:prompt="@string/spinner_prompt"
/>
3) Declare the spinner in the activity
Code:
Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.sensors, R.layout.spinnertext);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
//when an item is selected call the selectSensor method
s.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView parent, View view, int position, long id) {
selectSensor(parent.getItemAtPosition(position));
}
@Override
public void onNothingSelected(AdapterView arg0) {
}
});
Notice the change in the createfromresource function.

Categories

Resources