我有一个带有线性布局的scrollview。在线性布局中,我添加了5个项目(带有一些视图的线性布局)。充气时,它们比屏幕大。
我想在屏幕渲染时,项目5(最后一项)显示在屏幕顶部。怎么做?
我试过了:
<ScrollView
android:id="@+id/suggested_menu_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/suggested_menu_meals_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
但它不起作用。我在我的视图中检查了geTop(),getBottom(),getScrollY(),但都返回了0。
这是我的父布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/linear_suggested_meal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/cardview_default_radius"
android:layout_marginTop="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="4dp">
<ProgressBar
android:id="@+id/progress_suggested_meal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
style="@android:style/Widget.ProgressBar"
android:visibility="gone"
android:layout_gravity="center_vertical|center_horizontal" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/cards_padding_space">
<TextView
android:id="@+id/suggested_meal_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/black_soft"
android:text="Sugestão de café da manhã"
android:textStyle="bold" />
<TextView
android:id="@+id/suggested_meal_total_points"
style="@style/DSTextLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/suggested_meal_name"
android:layout_alignStart="@id/suggested_meal_name"
android:layout_alignLeft="@id/suggested_meal_name"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:text="@string/zero"
android:textSize="14sp"
android:textColor="@color/green_x"
android:textStyle="bold" />
<TextView
android:id="@+id/suggested_meal_suggested"
style="@style/DSTextSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/suggested_meal_total_points"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/suggested_meal_total_points"
android:layout_toEndOf="@id/suggested_meal_total_points"
android:textSize="14sp"
android:text="sugerido de "
android:textColor="@color/gray_opaque" />
<View
android:id="@+id/separator_suggested_meal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/suggested_meal_total_points"
android:background="@color/dividers" />
<LinearLayout
android:id="@+id/suggested_meal_food_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/separator_suggested_meal"
android:orientation="vertical"
android:layout_marginBottom="2dp"
/>
<LinearLayout
android:layout_marginTop="2dp"
android:paddingTop="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/suggested_meal_food_container"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/button_suggested_meal_next_suggestion"
style="@style/DSLinkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/button_suggested_meal_add"
style="@style/DSLinkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/horizontal_space_large"
android:layout_marginStart="20dp"
android:background="?attr/selectableItemBackground"
android:text="@string/button_meal_suggestion_label_add_suggest" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
这是我的项目布局:
<?php
include 'dbconnect.php';
if(isset($_POST['search'])) {
$valueToSearch = mysqli_real_escape_string($db, $_POST['valueToSearch']);
// search in all table columns
// using concat mysql function
$sql = "SELECT * FROM contacts
WHERE CONCAT(FirstName, Surname, Email, HomePhone, MobPhone)
LIKE '%".$valueToSearch."%'";
$query = mysqli_query($db,$sql);
} else {
$orderBy = "FirstName";
$order = "asc";
if(!empty($_GET["orderby"])) {
$orderBy = $_GET["orderby"];
}
if(!empty($_GET["order"])) {
$order = $_GET["order"];
}
$firstOrder = "asc";
$SurOrder = "asc";
$emailOrder = "desc";
if($orderBy == "FirstName" and $order == "asc") {
$firstOrder = "desc";
}
if($orderBy == "Surname" and $order == "asc") {
$surOrder = "desc";
}
if($orderBy == "Email" and $order == "desc") {
$emailOrder = "asc";
}
// Build an SQL Query
$sql = "SELECT * from contacts ORDER BY " . $orderBy . " " . $order;
// Run the Query
$query = mysqli_query($db,$sql);
}
?>
<form action="front-contact.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<form action='' method=post>
<table border='1'>
<tr>
<th><a href="?orderby=FirstName&order=<?php echo $firstOrder; ?>">First Name</a></th>
<th><a href="?orderby=Surname&order=<?php echo $surOrder; ?>">Surname</th>
<th><a href="?orderby=Email&order=<?php echo $emailOrder; ?>">Email Address</th>
<th>Home Number</th>
<th>Mobile Number</th>
</tr>
<?php
// Loop through each returned record and store the data in $row.. //
while ($row = mysqli_fetch_assoc($query)) {
// Output the column-name of $row using the array-notation //
echo "<form action='' method=post>";
echo "<tr>";
echo "<td>".$row['FirstName']."</td>";
echo "<td>".$row['Surname']."</td>";
echo "<td>".$row['Email']."</td>";
echo "<td>".$row['HomePhone']."</td>";
echo "<td>".$row['MobPhone']."</td>";
echo " </form>";
echo "</tr>";
}
echo "</table>";
?>
答案 0 :(得分:0)
试试这个
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});