Reputation: 133
On layout I have listview
<com...DynamicListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_weight="0.34"
android:background="#0000"
android:divider="@null"
android:dividerHeight="5dp" />
to which was added 4-th TextView. text_view.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="@dimen/list_text_size" />
How can I make them all the same height and climbed onto the screen on screens with different resolutions (without the appearance of the scroll)?
Update
public class StableArrayAdapter extends ArrayAdapter<String> {
public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
...
int myDPValue = 60;
myDPValue = (int) ((int) myDPValue * Resources.getSystem().getDisplayMetrics().density);
(LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, myDPValue);
view.setLayoutParams(params);
return view;
}
}
Upvotes: 0
Views: 369
Reputation: 3070
If you don't want to have scrolling, then you should not use a ListView
. You should use a LinearLayout
with vertical orientation instead, and use equal weights for the items if you want to have them resized to fit the available space on the screen.
Upvotes: 1
Reputation: 1483
If I understand the question correctly, you are looking to adjust the height based on the size of the screen of the various devices. For this, you can take advantage of the res/values/dimens.xml
file, along with how Android does resource configurations. You can redefine the same dimen
for each screen density or size that you'd like. See the following links for your answers:
Upvotes: 1