Posts

Showing posts with the label Layout

Android Spinner Dropdown Arrow Not Displaying

Answer : This works for me, much simpler as well: <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Light" android:spinnerMode="dropdown" /> And in your class file: spinner = (Spinner) view.findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); Hope this helps ;) Try this one: <Spinner android:id="@+id/spinnPhoneTypes" android:layout_width="0dp" style="@android:style/Widget.Spinner.DropDown" android:layout_height="@dimen/thirtyFive" android:layout_marginLeft="10dp" android:layout_weight="1...

Algorithm To Implement A Word Cloud Like Wordle

Answer : I'm the creator of Wordle. Here's how Wordle actually works: Count the words, throw away boring words, and sort by the count, descending. Keep the top N words for some N. Assign each word a font size proportional to its count. Generate a Java2D Shape for each word, using the Java2D API. Each word "wants" to be somewhere, such as "at some random x position in the vertical center". In decreasing order of frequency, do this for each word: place the word where it wants to be while it intersects any of the previously placed words move it one step along an ever-increasing spiral That's it. The hard part is in doing the intersection-testing efficiently, for which I use last-hit caching, hierarchical bounding boxes, and a quadtree spatial index (all of which are things you can learn more about with some diligent googling). Edit: As Reto Aebersold pointed out, there's now a book chapter, freely available, that covers this same terri...

Android SetVisibility Does Not Display If Initially Set To Invisble

Answer : Had similar error but it was due to my silly mistake of not using the UiThread. Activity act = (Activity)context; act.runOnUiThread(new Runnable(){ @Override public void run() { mLayoutLights.setVisibility(View.VISIBLE); } }); Got it. You have to set the visibility of all the items in the layout, not just the layout. So this code worked: if (mLayoutLights.getVisibility() == View.VISIBLE) { ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE); mLayoutLights.setVisibility(View.GONE); } else { mLayoutLights.setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE); } In my case, with a plain SurfaceView, I just set the View to GONE in xml, not INVISIBLE. Then I can set VISIBILITY correctly after that.

Android Relative Layout Center Vertical With Margin

Answer : Try this: Try to use RelativeLayout which can easily done your requirement using weight : <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical"> <TextView android:id="@id/dummy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <TextView android:layout_below="@id/dummy" android:layout_marginTop="10dp" android:text="This is TextView" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout> Try to use LinearLayout which can easily done your requirement using weight : <LinearLayout xmlns:and...