Basically the android list view activity is transparent well i have managed to make it solid black using custom layout but how do i make it like the third image where the corner colour will be random .
thanks in advance
MainActivity.java
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ArrayAdapter;
public class MainActivity extends Activity {
// Declare
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
private RelativeLayout headerPanel;
private int panelWidth;
private int panelWidth1;
private ImageView menuViewButton,menuRightButton;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters;
LinearLayout.LayoutParams listViewParameters;
//Example
////////
String[] Example = new String[]
{ "Android Introduction","Android Setup/Installation","Android Hello World",
"Android Layouts/Viewgroups","Android Activity & Lifecycle","Intents in Android"};
////////
//Example
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layer_stack);
// Initialize
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels) * -0.65);//Right panel width
panelWidth1 = (int) ((metrics.widthPixels) * 0.65);//left panel width
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel
.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel
.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
///////
ArrayAdapter<String> ExampleArrayAdapter = new CustomAdapter(this, Example);
//changing code//practice
/*new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
Example);*/
ListView ExampleListView = (ListView)findViewById(R.id.listView);
ExampleListView.setAdapter(ExampleArrayAdapter);
///////
// Slide the Panel
menuRightButton = (ImageView) findViewById(R.id.menuViewButton);
menuRightButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!isExpanded) {
isExpanded = true;
// Expand
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.menuPanel,
new LeftMenuFragment());
fragmentTransaction.commit();
new ExpandAnimation(slidingPanel, panelWidth1,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.65f, 0, 0.0f, 0, 0.0f);
} else {
isExpanded = false;
// Collapse
new CollapseAnimation(slidingPanel, panelWidth1,
TranslateAnimation.RELATIVE_TO_SELF, 0.65f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f,
0, 0.0f);
}
}
});
}
}
custom_layout.xml
<?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="70dp"
android:orientation="horizontal"
android:layout_marginTop="60dp"
android:background="@drawable/blue_bg">
<ImageView
android:id="@+id/imageView1"
android:layout_width="70dp"
android:layout_height="60dp"
android:src="@drawable/ic_launcher"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:gravity="left" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="19sp"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Tweet body text here"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:lines="3"
android:textColor="#ffffff"
android:textSize="14sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Small Text"
android:layout_marginTop="5dp"
android:textColor="#ffffff"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
CustomAdapter.java
public class CustomAdapter extends ArrayAdapter {
private LayoutInflater inflater;
public CustomAdapter (Activity activity, String[] items){
super(activity, R.layout.custom_layout, items);
inflater = activity.getWindow().getLayoutInflater();
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
return inflater.inflate(R.layout.custom_layout, parent, false);
}
}
I have managed to make it show random colour with updating the get view function with the following code but everytime i scroll the colour changes, how do i make it stable so that once the colour is assigned it won't change?
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
View rowView = inflater.inflate(R.layout.custom_layout, parent, false);
rowView.setBackgroundColor(color);