android:layout_height="0dp"
и будет ожидаемый вариант. Вообще при использовании android:layout_weight
у этого контрола желательно ставить android:layout_height
(или соответственно android:layout_width
) в 0dp. И поведение будет более предсказуемым, да и работает быстрее. А у нижнего ImageView android:layout_weight
наверное совсем не нужен. public class DashboardLayout extends ViewGroup {
private final static String TAG = DashboardLayout.class.getName();
private final static int DEFAULT_COLUMNS = 3;
private int columns;
public DashboardLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DashboardLayout);
try {
setColumns(a.getInt(R.styleable.DashboardLayout_dashboardColumns, DEFAULT_COLUMNS));
} finally {
a.recycle();
}
}
public DashboardLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DashboardLayout(Context context) {
this(context, null);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int totalChildWidth = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
int visibleCount = getVisibleCount();
if (visibleCount > 0) {
int childWidth = totalChildWidth / columns;
int childHeight = childWidth;
int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
int childHeightSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY);
for (int i = 0, N = getChildCount(); i < N; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.measure(childWidthSpec, childHeightSpec);
}
}
}
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childLeft = l + getPaddingLeft();
int childTop = t + getPaddingTop();
for (int i = 0, N = getChildCount(); i < N; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
childTop + child.getMeasuredHeight());
childLeft += child.getMeasuredWidth();
if (childLeft + getPaddingRight() >= r) {
childLeft = l + getPaddingLeft();
childTop += child.getMeasuredHeight();
}
}
}
}
/***
* Set number of columns. By default DashboardLayout uses 3 columns
*
* @param value
* - number of columns
*/
public void setColumns(int value) {
if (value != columns) {
columns = value;
requestLayout();
}
}
/***
* Returns number of columns.
*
* @return number of columns
*/
public int getColumns() {
return columns;
}
private int getVisibleCount() {
int count = 0;
for (int i = 0, N = getChildCount(); i < N; i++) {
if (getChildAt(i).getVisibility() != GONE) count++;
}
return count;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="DashboardLayout">
<attr name="dashboardColumns" format="integer" />
</declare-styleable>
</resources>
mList.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (visibleItemCount > 0 && firstVisibleItem + visibleItemCount == totalItemCount &&
hasNextPage()) {
loadNextPage();
}
}
});
private void takePicture() {
Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
...
private void downloadContent() {
HttpURLConnection connection = null;
BufferedInputStream ins = null;
String urlString = "<заданный адрес сайта>";
try {
URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
int status = connection.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) {
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
ins = new BufferedInputStream(connection.getInputStream());
parser.setInput(ins, null);
parseData(parser);
}
} catch (Exception e) {
// надо обработать исключение
} finally {
if (ins != null) {
try {
ins.close();
} catch (IOException e) {}
}
}
}
public void parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
int eventType = parser.getEventType();
final String xmlTag = "rootTAG";
do {
if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
if (xmlTag.equalsIgnoreCase(name) && (parser.getAttributeCount() > 0)) {
for (int i = 0, N = parser.getAttributeCount(); i < N; i++) {
// парсим атрибуты
parseAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
}
}
// парсим вложенный таг
parseTag(parser);
}
eventType = parser.next();
} while (!(eventType == XmlPullParser.END_TAG && xmlTag.equals(parser.getName()))
&& (eventType != XmlPullParser.END_DOCUMENT));
}
public class TestActivity extends ListActivity {
private final static String TITLE_KEY = "title";
private final static String DESCRIPTION_LEY = "description";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
int count = 10;
for (int i = 1; i <= count; i++) {
final HashMap<String, String> item = new HashMap<String, String>();
item.put(TITLE_KEY, String.format("Title %d", i));
item.put(DESCRIPTION_LEY, String.format("Description %d", i));
data.add(item);
}
setListAdapter(new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] { TITLE_KEY,
DESCRIPTION_LEY }, new int[] { android.R.id.text1, android.R.id.text2 }));
}
}
<?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="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data" />
</LinearLayout>