My xml (lvlayout.xml) layout for a listview is currently like this:
<TextView
android:id="#+id/busnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dip"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/servdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dip"
android:textColor="#23cf34" />
I populate the listview via a simplecursor adapter like this:
dueAdapter = new SimpleCursorAdapter(main.this, R.layout.lvlayout,
dueBusesCursor, columnsdue, to);
dueListView = (ListView) findViewById(R.id.ListView01);
dueListView.setAdapter(dueAdapter);
How can I make the listviews horizontal so that the user scrolls sideways ? thanks in advance.
ListView does not support the horizontal mode. The closest thing to a horizontal ListView is Gallery.
you can use ViewPager :
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
Related
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/titleImageViewID"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="#string/todo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/mac" />
<View
android:id="#+id/view8"
android:layout_width="0dp"
android:layout_height="86dp"
android:layout_marginTop="168dp"
android:background="#8A474141"
app:layout_constraintBottom_toBottomOf="#id/titleImageViewID"
app:layout_constraintEnd_toEndOf="#+id/titleImageViewID"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="#+id/titleImageViewID"
app:layout_constraintTop_toTopOf="#+id/titleImageViewID" />
<TextView
android:id="#+id/titleTextViewID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/textview"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/view8"
app:layout_constraintEnd_toEndOf="#+id/view8"
app:layout_constraintStart_toStartOf="#+id/view8"
app:layout_constraintTop_toBottomOf="#+id/titleImageViewID"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Above code is sample_layout of a RecyclerView - please suggest for only ConstraintLayout, I use this layout because this is responsive to any device, so I don't need to create another layout for different screen sizes
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private RecyclerView recyclerView;
private RecycleAdapter recycleAdapter;
private RecyclerView.LayoutManager manager;
private ConstraintLayout constraintLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycleViewID);
manager = new ConstraintLayout(this,ConstraintLayout,View.SCROLL_AXIS_HORIZONTAL,false);
RecycleModel [] myThumbData = new RecycleModel[]{
new RecycleModel("Goru banaisi", R.drawable.mac)};}
Can't figure out the main java code how do I access all of my XML in java code, anyone give me a proper code and explanation, I couldn't find any recycler view using constraint layout online. So problem solver help me to solve my problem**
LayoutManager
You have to set proper LayoutManager. There are few basic implementations e.g. LinearLayoutManager, GridLayoutManager or StaggeredGridLayoutManager.
In Android Documentation you can find information that:
A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user. By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more. Several stock layout managers are provided for general use.
Set from Code
You can set them from code:
layoutManager = new LinearLayoutManager(
this,
LinearLayoutManager.HORIZONTAL, // Here, you have orientation of items
false
);
// Remember to set your LayoutManager in recycler view, not in adapter!
recyclerView.setLayoutManager(layoutManager);
Set from XML
In your XML layout file, where you have your adapter, you have to set:
orientation and
layoutManager.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
Set your recyclerview manager as shown below:
manager = new LinearLayoutManager(this, RecyclerView.Horizontal, false)
reyclerview.manager = manager
//Then set the adapter
recyclerview.adapter = your adapter.
This should enable horizontal scroll for your recyclerview.
Hope this helps
i trying to get a layout just like the image below for a game in android studio
currently my xml is
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dreacot.testmymemory.Game">
<ImageView
android:id="#+id/imageView"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="285dp" />
i want more cards to be added on the next level eg lvl 2
do i need to make several layouts for each level?
also i want each card to show its face when it is clicked
and finally i feel i am not doing the right thing as i feel xml files cannot be called into the gameplay is there a better way to do this layout(maybe programmatically)?
could anyone help?
The way you are doing it is not the proper way to do it, In this way maybe you can achieve this for 6 cards. What if you have let's say 100 cards or may be 1000, will you add 100 images in Layout and get reference of 100 images in Activity and set Click Listeners and animations to turn the side on 100 images?
Use "GridView" and Adapter for your views, it will do your work with ease.
Check this: https://developer.android.com/guide/topics/ui/layout/gridview.html
You have to do it programmatically.
1. Use RecyclerView with GridLayoutManager to show your card as grid style.
2. Create a layout with just a CardView with single ImageView for your single card item.
3. Create an custom RecyclerView.Adapter<> and use it with RecyclerView to populate your card data on CardView.
4. Add onItemClick listener to Adapter to flip to the specific Card item and do something as per your needs.
Here are some useful links about RecyclerView:
Android RecyclerView with GridLayoutManager Example
Android GridLayoutManager with RecyclerView in Material Design
Simple Android grid example using RecyclerView with GridLayoutManager
Here is a good library for CardView animation.
Hope this will help~
I'm loading an AutoCompleteTextView with lots of items but none of them is shown/visible in the popup.
P.s.: If I click somewhere in that empty white view, the text appears in the AutoCompleteTextView (it's white text)
resource.xml
<AutoCompleteTextView
android:id="#+id/reg_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/input_register_bg"
android:hint="Città "
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_register"
android:textColorHint="#color/input_register_hint" />
activity.java
ArrayAdapter<String> citta_adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, list_cities);
in_city.setAdapter(citta_adapter);
Most probably the suggestions are white-on-white, which is why you're not seeing them, but pressing on a suggestion works.
See this for a list of possible solutions: AutoCompleteTextview Color set white by default
I have tried marquee limit 1 but it does not work
<TextView
android:id="#+id/marqueText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:gravity="center"
android:singleLine="true"
android:textSize="26sp" />
</RelativeLayout>
It seems to me that you are looking for the marquee animation. There is no XML attribute that you set for that purpose
This is a good link for the marquee animation in android. Hope it helps!
The XML attribute simply fades the textview if it goes out of your device screen.
Try using setSelected(true) method of TextView in onCreate()
TextView textView = (TextView) findViewById(R.id.marqueText);
textView.setSelected(true);
ListView
[Text] [Button 1][Button 2]
[Text] [Button 1][Button 2]
... (and so on) ...
Button 1 should be like Check Box and other button which allows to redirect on other page
Is above mentioned thing possible??
Thanks in advance..
Each row in a list view can have anything your heart desires. A row is basically defined as its own layout, and you can define the layout as you wish. In your case, you probably want to do a RelativeLayout. Check out the examples, they come pretty close to what you want.
You can have your ListView row to contain a CheckedTextView and a Button ina Linear Layout.
In \layout\ folder, define your customised my_row.xml, roughly so
<?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="horizontal">
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Then for populating your ListView, give this in your Adapter.
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this, R.layout.my_row, strings);
myList.setAdapter(myAdapter);